mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Mouse Events support https://github.com/seerge/g-helper/issues/2430
This commit is contained in:
@@ -21,12 +21,35 @@ public sealed class KeyboardHook : IDisposable
|
|||||||
private const byte VK_LWIN = 0x5B;
|
private const byte VK_LWIN = 0x5B;
|
||||||
private const byte VK_LCONTROL = 0xA2;
|
private const byte VK_LCONTROL = 0xA2;
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
|
||||||
|
//Mouse actions
|
||||||
|
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
|
||||||
|
private const int MOUSEEVENTF_LEFTUP = 0x04;
|
||||||
|
|
||||||
|
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
|
||||||
|
private const int MOUSEEVENTF_RIGHTUP = 0x10;
|
||||||
|
|
||||||
|
private const int MOUSEEVENTF_MIDDOWN = 0x20;
|
||||||
|
private const int MOUSEEVENTF_MIDTUP = 0x40;
|
||||||
|
|
||||||
public static void KeyPress(Keys key)
|
public static void KeyPress(Keys key)
|
||||||
{
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Keys.LButton:
|
||||||
|
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
|
||||||
|
return;
|
||||||
|
case Keys.RButton:
|
||||||
|
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
|
||||||
|
return;
|
||||||
|
case Keys.MButton:
|
||||||
|
mouse_event(MOUSEEVENTF_MIDDOWN | MOUSEEVENTF_MIDTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
|
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
|
||||||
|
|
||||||
Thread.Sleep(1);
|
Thread.Sleep(1);
|
||||||
|
|
||||||
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
|
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user