Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Windows;
- namespace NumpadMouseEmul
- {
- class Program
- {
- class Win32
- {
- public const uint MOUSEEVENTF_ABSOLUTE = 0x8000;
- public const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
- public const uint MOUSEEVENTF_LEFTUP = 0x0004;
- public const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020;
- public const uint MOUSEEVENTF_MIDDLEUP = 0x0040;
- public const uint MOUSEEVENTF_MOVE = 0x0001;
- public const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;
- public const uint MOUSEEVENTF_RIGHTUP = 0x0010;
- public const uint MOUSEEVENTF_XDOWN = 0x0080;
- public const uint MOUSEEVENTF_XUP = 0x0100;
- public const uint MOUSEEVENTF_WHEEL = 0x0800;
- public const uint MOUSEEVENTF_HWHEEL = 0x01000;
- [DllImport("user32.dll")]
- public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
- // Check mouse buttons & keys if pressed
- [DllImport("user32.dll")]
- public static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
- }
- [DllImport("User32.dll")]
- private static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey); // Keys enumeration
- [DllImport("User32.dll")]
- private static extern short GetAsyncKeyState(System.Int32 vKey);
- [DllImport("user32.dll", SetLastError = true)]
- static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
- public static void PressKey(Keys key, bool up)
- {
- const int KEYEVENTF_EXTENDEDKEY = 0x1;
- const int KEYEVENTF_KEYUP = 0x2;
- if (up)
- {
- keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
- }
- else
- {
- keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
- }
- }
- static void Main(string[] args)
- {
- while (true)
- {
- if (Win32.GetAsyncKeyState(Keys.LButton) != 0)
- {
- PressKey(Keys.NumPad5, true);
- Thread.Sleep(2);
- PressKey(Keys.NumPad5, false);
- Console.Write(5);
- }
- Thread.Sleep(20);
- if (Win32.GetAsyncKeyState(Keys.RButton) != 0)
- {
- PressKey(Keys.NumPad4, true);
- Thread.Sleep(2);
- PressKey(Keys.NumPad4, false);
- Console.Write(4);
- }
- Thread.Sleep(20);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment