-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouseOperations.cs
50 lines (42 loc) · 1.42 KB
/
MouseOperations.cs
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
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace AutoClicker;
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "Library")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Library")]
internal static class MouseOperations
{
[Flags]
public enum EventFlag
{
Move = 0x00000001,
LeftDown = 0x00000002,
LeftUp = 0x00000004,
RightDown = 0x00000008,
RightUp = 0x00000010,
MiddleDown = 0x00000020,
MiddleUp = 0x00000040,
Absolute = 0x00008000,
Click = LeftDown | LeftUp,
}
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetCursorPosition(out Point point);
public static Point GetCursorPosition()
{
if (!GetCursorPosition(out var currentMousePoint))
{
currentMousePoint = new();
}
return currentMousePoint;
}
[DllImport("user32.dll", EntryPoint = "mouse_event")]
private static extern void Event(int dwFlags, int dx, int dy, int dwData = 0, int dwExtraInfo = 0);
public static void Event(EventFlag value)
{
var position = GetCursorPosition();
Event((int)value, position.X, position.Y);
}
[StructLayout(LayoutKind.Sequential)]
public readonly record struct Point(int X, int Y);
}