Skip to content

Commit 541b650

Browse files
authored
Merge pull request #39 from lucassklp/update-version
Publish version, rearrange code and fix #37
2 parents e957226 + 229e040 commit 541b650

File tree

8 files changed

+39
-38
lines changed

8 files changed

+39
-38
lines changed

Desktop.Robot/AbstractRobot.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ public abstract class AbstractRobot : IRobot
2323

2424
public abstract void KeyUp(char key);
2525

26-
public abstract void MouseMove(uint x, uint y);
26+
public abstract void MouseMove(int x, int y);
27+
28+
public abstract void MouseScrollVertical(int value);
2729

2830
public void MouseMove(Point p)
2931
{
30-
MouseMove((uint)p.X, (uint)p.Y);
32+
MouseMove(p.X, p.Y);
3133
}
3234

3335
public virtual Image CreateScreenCapture(Rectangle screenRect)
@@ -38,7 +40,7 @@ public virtual Image CreateScreenCapture(Rectangle screenRect)
3840
return bmp;
3941
}
4042

41-
public virtual Color GetPixelColor(uint x, uint y)
43+
public virtual Color GetPixelColor(int x, int y)
4244
{
4345
var rect = new Rectangle(new Point((int)x, (int)y), new Size(1, 1));
4446
return (CreateScreenCapture(rect) as Bitmap).GetPixel(0, 0);
@@ -74,7 +76,5 @@ protected void ApplyAutoDelay()
7476
Thread.Sleep((int)AutoDelay);
7577
}
7678
}
77-
78-
public abstract void MouseScrollVertical(int value);
7979
}
8080
}

Desktop.Robot/Desktop.Robot.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net6.0</TargetFramework>
4-
<Version>1.3.2</Version>
4+
<Version>1.4.0</Version>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66
<Authors>Lucas Simas</Authors>
77
<Description>A library used to control your mouse and keyboard programmatically in .NET Core</Description>

Desktop.Robot/Extensions/BezierMouseMovementExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void BezierMovement(this IRobot robot, Point initial, Point contro
5959
robot.MouseMove(point);
6060
}
6161

62-
robot.MouseMove((uint)ending.X, (uint)ending.Y);
62+
robot.MouseMove(ending.X, ending.Y);
6363

6464
robot.AutoDelay = currentAutoDelay;
6565
}

Desktop.Robot/IRobot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface IRobot
77
{
88
uint AutoDelay { get; set; }
99
Image CreateScreenCapture(Rectangle screenRect);
10-
Color GetPixelColor(uint x, uint y);
10+
Color GetPixelColor(int x, int y);
1111
void KeyPress(Key key);
1212
void KeyPress(char key);
1313
void KeyDown(Key key);
@@ -18,7 +18,7 @@ public interface IRobot
1818
void MouseDown(IClick click);
1919
void MouseUp(IClick click);
2020
void Delay(uint ms);
21-
void MouseMove(uint x, uint y);
21+
void MouseMove(int x, int y);
2222
void MouseMove(Point p);
2323
void MouseScrollVertical(int value);
2424
Point GetMousePosition();

Desktop.Robot/Linux/Robot.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override void KeyDown(Key key)
2929
public override void KeyDown(char key)
3030
{
3131
ApplyAutoDelay();
32-
var flags = Char.IsUpper(key) ? (1 << 0) : 0;
32+
var flags = char.IsUpper(key) ? (1 << 0) : 0;
3333
pressKey(key, true, flags);
3434
}
3535

@@ -44,7 +44,7 @@ public override void KeyPress(Key key)
4444
public override void KeyPress(char key)
4545
{
4646
ApplyAutoDelay();
47-
var flags = Char.IsUpper(key) ? (1 << 0) : 0;
47+
var flags = char.IsUpper(key) ? (1 << 0) : 0;
4848
pressKey(key, true, flags);
4949
pressKey(key, false, flags);
5050
}
@@ -59,13 +59,30 @@ public override void KeyUp(Key key)
5959
public override void KeyUp(char key)
6060
{
6161
ApplyAutoDelay();
62-
var flags = Char.IsUpper(key) ? (1 << 0) : 0;
62+
var flags = char.IsUpper(key) ? (1 << 0) : 0;
6363
pressKey(key, false, flags);
6464
}
65-
public override void MouseMove(uint x, uint y)
65+
66+
public override void MouseMove(int x, int y)
6667
{
6768
ApplyAutoDelay();
68-
moveMouse((int)x, (int)y);
69+
moveMouse(x, y);
70+
}
71+
72+
public override void MouseScrollVertical(int value)
73+
{
74+
if (value < 0)
75+
{
76+
click(true, Common.UP_BUTTON);
77+
Thread.Sleep(value);
78+
click(false, Common.UP_BUTTON);
79+
}
80+
else
81+
{
82+
click(true, Common.DOWN_BUTTON);
83+
Thread.Sleep(value);
84+
click(false, Common.DOWN_BUTTON);
85+
}
6986
}
7087

7188

@@ -86,21 +103,5 @@ public override void MouseMove(uint x, uint y)
86103

87104
[DllImport("./x11.os", EntryPoint = "pressKeyCode")]
88105
private static extern IntPtr pressKeyCode(int code, bool down, int flags);
89-
90-
public override void MouseScrollVertical(int value)
91-
{
92-
if (value < 0)
93-
{
94-
click(true, Common.UP_BUTTON);
95-
Thread.Sleep(value);
96-
click(false, Common.UP_BUTTON);
97-
}
98-
else
99-
{
100-
click(true, Common.DOWN_BUTTON);
101-
Thread.Sleep(value);
102-
click(false, Common.DOWN_BUTTON);
103-
}
104-
}
105106
}
106107
}

Desktop.Robot/OSX/Robot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public override void KeyUp(char key)
4646
keyUp(key);
4747
}
4848

49-
public override void MouseMove(uint x, uint y)
49+
public override void MouseMove(int x, int y)
5050
{
5151
ApplyAutoDelay();
5252
setMousePosition(x, y);
@@ -73,7 +73,7 @@ public override void MouseScrollVertical(int value)
7373
}
7474

7575
[DllImport("./osx.os", EntryPoint = "setMousePosition")]
76-
private static extern void setMousePosition(uint x, uint y);
76+
private static extern void setMousePosition(int x, int y);
7777

7878
[DllImport("./osx.os", EntryPoint = "getMousePosition")]
7979
private static extern IntPtr getMousePosition();

Desktop.Robot/Robot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public Point GetMousePosition()
5151
return robot.GetMousePosition();
5252
}
5353

54-
public Color GetPixelColor(uint x, uint y)
54+
public Color GetPixelColor(int x, int y)
5555
{
5656
return robot.GetPixelColor(x, y);
5757
}
@@ -92,7 +92,7 @@ public void MouseDown(IClick click)
9292
robot.MouseDown(click);
9393
}
9494

95-
public void MouseMove(uint x, uint y)
95+
public void MouseMove(int x, int y)
9696
{
9797
robot.MouseMove(x, y);
9898
}

Desktop.Robot/Windows/Robot.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ public override void KeyUp(char key)
6464
keybd_event(keycode, 0, 2, 0);
6565
}
6666

67-
public override void MouseMove(uint x, uint y)
67+
public override void MouseMove(int x, int y)
6868
{
6969
ApplyAutoDelay();
7070
SetCursorPos(x, y);
7171
}
7272

7373
[DllImport("user32.dll")]
7474
[return: MarshalAs(UnmanagedType.Bool)]
75-
static extern bool SetCursorPos(uint x, uint y);
75+
static extern bool SetCursorPos(int x, int y);
7676

7777

7878
[StructLayout(LayoutKind.Sequential)]
@@ -179,8 +179,8 @@ public override void MouseScrollVertical(int value)
179179
MouseInputWithUnion = new MouseInput(value, MouseState.MouseWheelUpDown)
180180
}
181181
};
182-
var responce = SendInput(1, input, Marshal.SizeOf(input));
183-
Debug.Assert(responce == 0);
182+
var response = SendInput(1, input, Marshal.SizeOf(input));
183+
Debug.Assert(response == 0);
184184
}
185185
}
186186
}

0 commit comments

Comments
 (0)