-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseCommand.cs
More file actions
79 lines (68 loc) · 3.21 KB
/
MouseCommand.cs
File metadata and controls
79 lines (68 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//-------------------------------------------------------------------
// Copyright © 2012 Kindel Systems, LLC
// http://www.kindel.com
// charlie@kindel.com
//
// Published under the MIT License.
// Source control on SourceForge
// http://sourceforge.net/projects/mcecontroller/
//-------------------------------------------------------------------
using System;
using System.Globalization;
using System.Xml.Serialization;
using WindowsInput;
using WindowsInput.Native;
namespace MCEControl
{
/// <summary>
/// Simulates mouse movements.
/// </summary>
class MouseCommand : Command
{
private string _action;
private string[] _parameters;
public static readonly string CmdPrefix = "mouse:";
public MouseCommand(string cmd)
{
_parameters = cmd.Substring(CmdPrefix.Length, cmd.Length - CmdPrefix.Length).Split(',');
if (_parameters.Length > 0)
_action = _parameters[0];
}
public override void Execute(Reply reply)
{
var sim = new InputSimulator();
// Format is "mouse:<action>[,<parameters>]
switch (_action)
{
case "lbc": sim.Mouse.LeftButtonClick(); break;
case "lbdc": sim.Mouse.LeftButtonDoubleClick(); break;
case "lbd": sim.Mouse.LeftButtonDown(); break;
case "lbu": sim.Mouse.LeftButtonUp(); break;
case "rbc": sim.Mouse.RightButtonClick(); break;
case "rbdc": sim.Mouse.RightButtonDoubleClick(); break;
case "rbd": sim.Mouse.RightButtonDown(); break;
case "rbu": sim.Mouse.RightButtonUp(); break;
// "mouse:xbc,3" - Mouse button 3 click
case "xbc": sim.Mouse.XButtonClick(GetIntOrZero(_parameters, 1)); break;
case "xbdc": sim.Mouse.XButtonDoubleClick(GetIntOrZero(_parameters, 1)); break;
case "xbd": sim.Mouse.XButtonDown(GetIntOrZero(_parameters, 1)); break;
case "xbu": sim.Mouse.XButtonUp(GetIntOrZero(_parameters, 1)); break;
// "mouse:mb,15,20" - Move mouse 15 in X direction, and 20 in Y direction
case "mm": sim.Mouse.MoveMouseBy(GetIntOrZero(_parameters, 1), GetIntOrZero(_parameters, 2)); break;
// "mouse:mt,812,562" - Move mouse to (812,562) on the screen
case "mt": sim.Mouse.MoveMouseTo(GetIntOrZero(_parameters, 1), GetIntOrZero(_parameters, 2)); break;
// "mouse:mtv,812,562" - Move mouse to (812,562) on the virtual desktop screen
case "mtv": sim.Mouse.MoveMouseToPositionOnVirtualDesktop(GetIntOrZero(_parameters, 1), GetIntOrZero(_parameters, 2)); break;
case "hs": sim.Mouse.HorizontalScroll(GetIntOrZero(_parameters, 1)); break;
case "vs": sim.Mouse.VerticalScroll(GetIntOrZero(_parameters, 1)); break;
}
}
private int GetIntOrZero(string[] s, int index)
{
int val = 0;
if (index >= s.Length) return val;
int.TryParse(s[index], out val);
return val;
}
}
}