PhotoShaman

NumpadMouseEmul

Oct 26th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Windows;
  10.  
  11. namespace NumpadMouseEmul
  12. {
  13.     class Program
  14.     {
  15.         class Win32
  16.         {
  17.             public const uint MOUSEEVENTF_ABSOLUTE = 0x8000;
  18.             public const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
  19.             public const uint MOUSEEVENTF_LEFTUP = 0x0004;
  20.             public const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020;
  21.             public const uint MOUSEEVENTF_MIDDLEUP = 0x0040;
  22.             public const uint MOUSEEVENTF_MOVE = 0x0001;
  23.             public const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;
  24.             public const uint MOUSEEVENTF_RIGHTUP = 0x0010;
  25.             public const uint MOUSEEVENTF_XDOWN = 0x0080;
  26.             public const uint MOUSEEVENTF_XUP = 0x0100;
  27.             public const uint MOUSEEVENTF_WHEEL = 0x0800;
  28.             public const uint MOUSEEVENTF_HWHEEL = 0x01000;
  29.             [DllImport("user32.dll")]
  30.             public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
  31.             // Check mouse buttons & keys if pressed
  32.             [DllImport("user32.dll")]
  33.             public static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
  34.         }
  35.  
  36.         [DllImport("User32.dll")]
  37.         private static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey); // Keys enumeration
  38.         [DllImport("User32.dll")]
  39.         private static extern short GetAsyncKeyState(System.Int32 vKey);
  40.  
  41.         [DllImport("user32.dll", SetLastError = true)]
  42.         static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
  43.         public static void PressKey(Keys key, bool up)
  44.         {
  45.             const int KEYEVENTF_EXTENDEDKEY = 0x1;
  46.             const int KEYEVENTF_KEYUP = 0x2;
  47.             if (up)
  48.             {
  49.                 keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
  50.             }
  51.             else
  52.             {
  53.                 keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
  54.             }
  55.         }
  56.  
  57.         static void Main(string[] args)
  58.         {
  59.             while (true)
  60.             {
  61.                 if (Win32.GetAsyncKeyState(Keys.LButton) != 0)
  62.                 {
  63.                     PressKey(Keys.NumPad5, true);
  64.                     Thread.Sleep(2);
  65.                     PressKey(Keys.NumPad5, false);
  66.                     Console.Write(5);
  67.                 }
  68.                 Thread.Sleep(20);
  69.                 if (Win32.GetAsyncKeyState(Keys.RButton) != 0)
  70.                 {
  71.                     PressKey(Keys.NumPad4, true);
  72.                     Thread.Sleep(2);
  73.                     PressKey(Keys.NumPad4, false);
  74.                     Console.Write(4);
  75.                 }
  76.                 Thread.Sleep(20);
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment