Skip to content

Commit eb89523

Browse files
authored
arm support (#44)
1 parent c1e0abe commit eb89523

File tree

9 files changed

+431
-113
lines changed

9 files changed

+431
-113
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343
"sstream": "cpp",
4444
"stdexcept": "cpp",
4545
"streambuf": "cpp"
46-
}
46+
},
47+
"dotnet.defaultSolution": "Desktop.Robot.sln"
4748
}

Desktop.Robot/Desktop.Robot.csproj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424
</ItemGroup>
2525

2626
<ItemGroup>
27-
<None Include="osx.os">
28-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29-
<PackagePath>build\</PackagePath>
30-
<Pack>true</Pack>
31-
</None>
27+
<None Include="osx.os">
28+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29+
<PackagePath>build\</PackagePath>
30+
<Pack>true</Pack>
31+
</None>
32+
<None Include="osx_arm.os">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
<PackagePath>build\</PackagePath>
35+
<Pack>true</Pack>
36+
</None>
3237
<None Include="x11.os">
3338
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3439
<PackagePath>build\</PackagePath>

Desktop.Robot/Desktop.Robot.targets

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
<Link>osx.os</Link>
66
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
77
</None>
8+
<None Include="$(MSBuildThisFileDirectory)osx_arm.os">
9+
<Link>osx_arm.os</Link>
10+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
11+
</None>
812
<None Include="$(MSBuildThisFileDirectory)x11.os">
913
<Link>x11.os</Link>
1014
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1115
</None>
1216
</ItemGroup>
13-
</Project>
17+
</Project>

Desktop.Robot/OSX/Arm/Robot.cs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using System.Threading;
6+
7+
namespace Desktop.Robot.OSX.Arm
8+
{
9+
public class Robot : AbstractRobot
10+
{
11+
public override void KeyDown(Key key)
12+
{
13+
ApplyAutoDelay();
14+
var keycode = (ushort)key.GetKeycode().Keycode;
15+
sendCommandDown(keycode);
16+
}
17+
18+
public override void KeyDown(char key)
19+
{
20+
ApplyAutoDelay();
21+
keyDown(key);
22+
}
23+
24+
public override void KeyPress(Key key)
25+
{
26+
ApplyAutoDelay();
27+
var keycode = (ushort)key.GetKeycode().Keycode;
28+
sendCommand(keycode);
29+
}
30+
31+
public override void KeyPress(char key)
32+
{
33+
ApplyAutoDelay();
34+
keyPress(key);
35+
}
36+
37+
public override void KeyUp(Key key)
38+
{
39+
ApplyAutoDelay();
40+
var keycode = (ushort)key.GetKeycode().Keycode;
41+
sendCommandUp(keycode);
42+
}
43+
44+
public override void KeyUp(char key)
45+
{
46+
ApplyAutoDelay();
47+
keyUp(key);
48+
}
49+
50+
public override void MouseMove(int x, int y)
51+
{
52+
ApplyAutoDelay();
53+
setMousePosition(x, y);
54+
}
55+
56+
public override Point GetMousePosition()
57+
{
58+
var pos = Marshal.PtrToStringAnsi(getMousePosition());
59+
var coords = pos.Split(";")
60+
.Select(x => Convert.ToInt32(x))
61+
.ToArray();
62+
63+
var res = Marshal.PtrToStringAnsi(screenResolution());
64+
var screenRes = res.Split("x")
65+
.Select(x => Convert.ToInt32(x))
66+
.ToArray();
67+
68+
return new Point(coords[0], screenRes[1] - coords[1]);
69+
}
70+
71+
public override void MouseScroll(int value)
72+
{
73+
ApplyAutoDelay();
74+
DoMouseScroll(value);
75+
}
76+
77+
public override void MouseScroll(int value, TimeSpan duration)
78+
{
79+
MouseScroll(value, duration, 50);
80+
}
81+
82+
public override void MouseScroll(int value, TimeSpan duration, int steps)
83+
{
84+
ApplyAutoDelay();
85+
for (int i = 0; i < steps; i++)
86+
{
87+
Thread.Sleep(duration / steps);
88+
DoMouseScroll(value / steps);
89+
}
90+
}
91+
92+
private void DoMouseScroll(int value)
93+
{
94+
verticalScroll(value);
95+
}
96+
97+
[DllImport("./osx_arm.os", EntryPoint = "setMousePosition")]
98+
private static extern void setMousePosition(int x, int y);
99+
100+
[DllImport("./osx_arm.os", EntryPoint = "getMousePosition")]
101+
private static extern IntPtr getMousePosition();
102+
103+
[DllImport("./osx_arm.os", EntryPoint = "screenResolution")]
104+
private static extern IntPtr screenResolution();
105+
106+
[DllImport("./osx_arm.os", EntryPoint = "keyPress")]
107+
private static extern void keyPress(char ch);
108+
109+
[DllImport("./osx_arm.os", EntryPoint = "keyUp")]
110+
private static extern void keyUp(char ch);
111+
112+
[DllImport("./osx_arm.os", EntryPoint = "keyDown")]
113+
private static extern void keyDown(char ch);
114+
115+
[DllImport("./osx_arm.os", EntryPoint = "sendCommand")]
116+
private static extern void sendCommand(ushort ch);
117+
118+
[DllImport("./osx_arm.os", EntryPoint = "sendCommandUp")]
119+
private static extern void sendCommandUp(ushort ch);
120+
121+
[DllImport("./osx_arm.os", EntryPoint = "sendCommandDown")]
122+
private static extern void sendCommandDown(ushort ch);
123+
124+
[DllImport("./osx_arm.os", EntryPoint = "verticalScroll")]
125+
private static extern void verticalScroll(int value);
126+
127+
}
128+
}

Desktop.Robot/OSX/Intel/Robot.cs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using System.Threading;
6+
7+
namespace Desktop.Robot.OSX.Intel
8+
{
9+
public class Robot : AbstractRobot
10+
{
11+
public override void KeyDown(Key key)
12+
{
13+
ApplyAutoDelay();
14+
var keycode = (ushort)key.GetKeycode().Keycode;
15+
sendCommandDown(keycode);
16+
}
17+
18+
public override void KeyDown(char key)
19+
{
20+
ApplyAutoDelay();
21+
keyDown(key);
22+
}
23+
24+
public override void KeyPress(Key key)
25+
{
26+
ApplyAutoDelay();
27+
var keycode = (ushort)key.GetKeycode().Keycode;
28+
sendCommand(keycode);
29+
}
30+
31+
public override void KeyPress(char key)
32+
{
33+
ApplyAutoDelay();
34+
keyPress(key);
35+
}
36+
37+
public override void KeyUp(Key key)
38+
{
39+
ApplyAutoDelay();
40+
var keycode = (ushort)key.GetKeycode().Keycode;
41+
sendCommandUp(keycode);
42+
}
43+
44+
public override void KeyUp(char key)
45+
{
46+
ApplyAutoDelay();
47+
keyUp(key);
48+
}
49+
50+
public override void MouseMove(int x, int y)
51+
{
52+
ApplyAutoDelay();
53+
setMousePosition(x, y);
54+
}
55+
56+
public override Point GetMousePosition()
57+
{
58+
var pos = Marshal.PtrToStringAnsi(getMousePosition());
59+
var coords = pos.Split(";")
60+
.Select(x => Convert.ToInt32(x))
61+
.ToArray();
62+
63+
var res = Marshal.PtrToStringAnsi(screenResolution());
64+
var screenRes = res.Split("x")
65+
.Select(x => Convert.ToInt32(x))
66+
.ToArray();
67+
68+
return new Point(coords[0], screenRes[1] - coords[1]);
69+
}
70+
71+
public override void MouseScroll(int value)
72+
{
73+
ApplyAutoDelay();
74+
DoMouseScroll(value);
75+
}
76+
77+
public override void MouseScroll(int value, TimeSpan duration)
78+
{
79+
MouseScroll(value, duration, 50);
80+
}
81+
82+
public override void MouseScroll(int value, TimeSpan duration, int steps)
83+
{
84+
ApplyAutoDelay();
85+
for (int i = 0; i < steps; i++)
86+
{
87+
Thread.Sleep(duration / steps);
88+
DoMouseScroll(value / steps);
89+
}
90+
}
91+
private void DoMouseScroll(int value)
92+
{
93+
verticalScroll(value);
94+
}
95+
96+
[DllImport("./osx.os", EntryPoint = "setMousePosition")]
97+
private static extern void setMousePosition(int x, int y);
98+
99+
[DllImport("./osx.os", EntryPoint = "getMousePosition")]
100+
private static extern IntPtr getMousePosition();
101+
102+
[DllImport("./osx.os", EntryPoint = "screenResolution")]
103+
private static extern IntPtr screenResolution();
104+
105+
[DllImport("./osx.os", EntryPoint = "keyPress")]
106+
private static extern void keyPress(char ch);
107+
108+
[DllImport("./osx.os", EntryPoint = "keyUp")]
109+
private static extern void keyUp(char ch);
110+
111+
[DllImport("./osx.os", EntryPoint = "keyDown")]
112+
private static extern void keyDown(char ch);
113+
114+
[DllImport("./osx.os", EntryPoint = "sendCommand")]
115+
private static extern void sendCommand(ushort ch);
116+
117+
[DllImport("./osx.os", EntryPoint = "sendCommandUp")]
118+
private static extern void sendCommandUp(ushort ch);
119+
120+
[DllImport("./osx.os", EntryPoint = "sendCommandDown")]
121+
private static extern void sendCommandDown(ushort ch);
122+
123+
[DllImport("./osx.os", EntryPoint = "verticalScroll")]
124+
private static extern void verticalScroll(int value);
125+
126+
}
127+
}

0 commit comments

Comments
 (0)