Guest User

keylet

a guest
Nov 4th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 26.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Windows.Input;
  10.  
  11.  
  12.  
  13. using System.Runtime.InteropServices;
  14.  
  15. using System.Diagnostics;
  16. using System.IO;
  17. using System.Threading;
  18.  
  19. namespace keysGauntlet
  20. {
  21.     public partial class Form1 : Form
  22.     {
  23.        
  24.         [DllImport("user32.dll")]
  25.         static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData,
  26.            int dwExtraInfo);
  27.         // Get a handle to an application window.
  28.         [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
  29.         public static extern IntPtr FindWindow(string lpClassName,
  30.             string lpWindowName);
  31.  
  32.         [DllImport("user32.dll")]
  33.         private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
  34.  
  35.         [DllImport("user32.dll")]
  36.         private static extern bool UnhookWindowsHookEx(IntPtr hhk);
  37.  
  38.         [DllImport("user32.dll")]
  39.         private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
  40.  
  41.         [DllImport("kernel32.dll")]
  42.         private static extern IntPtr GetModuleHandle(string lpModuleName);
  43.  
  44.         [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
  45.         internal static extern short GetKeyState(int virtualKeyCode);
  46.  
  47.         // Activate an application window.
  48.         [DllImport("USER32.DLL")]
  49.         public static extern bool SetForegroundWindow(IntPtr hWnd);
  50.  
  51.         [DllImport("user32.dll")]
  52.         static extern IntPtr GetMessageExtraInfo();
  53.         [DllImport("user32.dll")]
  54.         static extern UInt32 SendInput(UInt32 nInputs, [MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] INPUT[] pInputs, Int32 cbSize);
  55.         /* enumerate windows*/
  56.         delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);
  57.  
  58.         [DllImport("user32.dll")]
  59.         static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn,
  60.             IntPtr lParam);
  61.  
  62.         static IEnumerable<IntPtr> EnumerateProcessWindowHandles(int processId)
  63.         {
  64.             var handles = new List<IntPtr>();
  65.  
  66.             foreach (ProcessThread thread in Process.GetProcessById(processId).Threads)
  67.                 EnumThreadWindows(thread.Id,
  68.                     (hWnd, lParam) => { handles.Add(hWnd); return true; }, IntPtr.Zero);
  69.  
  70.             return handles;
  71.         }
  72.  
  73.         private const uint WM_GETTEXT = 0x000D;
  74.  
  75.         [DllImport("user32.dll", CharSet = CharSet.Auto)]
  76.         static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam,
  77.             StringBuilder lParam);
  78.         private const int WH_KEYBOARD_LL = 13;
  79.         private const int WH_GETMESSAGE = 3;
  80.  
  81.  
  82.         private const int WM_KEYDOWN = 0x0100;
  83.         private const int WM_KEYUP = 0x0101;
  84.        
  85.         private static LowLevelKeyboardProc hookProc2 = HookCallback2;
  86.         private static IntPtr hookId = IntPtr.Zero;
  87.         public IntPtr moduleHandle;
  88.         public class Win32
  89.         {
  90.             [DllImport("User32.Dll")]
  91.             public static extern long SetCursorPos(int x, int y);
  92.  
  93.             [DllImport("User32.Dll")]
  94.             public static extern bool ClientToScreen(IntPtr hWnd, ref POINT point);
  95.  
  96.             [StructLayout(LayoutKind.Sequential)]
  97.             public struct POINT
  98.             {
  99.                 public int x;
  100.                 public int y;
  101.             }
  102.         }
  103.         [Flags]
  104.         private enum KeyStates
  105.         {
  106.             None = 0,
  107.             Down = 1,
  108.             Toggled = 2
  109.         }
  110.  
  111.  
  112.         private static KeyStates GetKeyState(Keys key)
  113.         {
  114.             KeyStates state = KeyStates.None;
  115.  
  116.             short retVal = GetKeyState((int)key);
  117.  
  118.             //If the high-order bit is 1, the key is down
  119.             //otherwise, it is up.
  120.             if ((retVal & 0x8000) == 0x8000)
  121.                 state |= KeyStates.Down;
  122.  
  123.             //If the low-order bit is 1, the key is toggled.
  124.             if ((retVal & 1) == 1)
  125.                 state |= KeyStates.Toggled;
  126.  
  127.             return state;
  128.         }
  129.  
  130.         public static bool IsKeyDown(Keys key)
  131.         {
  132.             return KeyStates.Down == (GetKeyState(key) & KeyStates.Down);
  133.         }
  134.  
  135.         public static bool IsKeyToggled(Keys key)
  136.         {
  137.             return KeyStates.Toggled == (GetKeyState(key) & KeyStates.Toggled);
  138.         }
  139.         private static IntPtr SetHook(LowLevelKeyboardProc hookProc, IntPtr moduleHandle)
  140.         {
  141.  
  142.             return SetWindowsHookEx(WH_KEYBOARD_LL, hookProc, moduleHandle, 0);
  143.         }
  144.  
  145.         private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
  146.         public Form1()
  147.         {
  148.             InitializeComponent();
  149.         }
  150.  
  151.         private void Form1_Load(object sender, EventArgs e)
  152.         {
  153.             moduleHandle = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);
  154.             hookId = SetHook(hookProc2, moduleHandle);
  155.         }
  156.  
  157.         private static IntPtr HookCallback2(int nCode, IntPtr wParam, IntPtr lParam)
  158.         {
  159.             int vkCode = Marshal.ReadInt32(lParam);
  160.             int returnMe = 0;
  161.             /* user details */
  162.             //-----------------Movement
  163.             //W
  164.             string key_W = "F1";
  165.             //A
  166.             string key_A = "F4";
  167.             //S
  168.             string key_S = "F3";
  169.             //D
  170.             string key_D = "F2";
  171.             //-----------------Spells
  172.             //Left click
  173.             string key_LClick = "F12";
  174.             //Right click
  175.             string key_RClick = "F8";
  176.             //Left shift
  177.             string key_LShift = "F10";
  178.             //Space
  179.             string key_Space = "F9";
  180.             //esc
  181.             string key_Esc = "F11";
  182.             //-----------------Other
  183.             //Relic 1 Q
  184.             string key_Q = "F6";
  185.             //Relic 2 E
  186.             string key_E = "F7";
  187.             //Interact F
  188.             string key_F = "F5";
  189.             //-----------------Resolution
  190.             int resolution_Height = 1080;
  191.             int resolution_Width = 1920;
  192.  
  193.            
  194.             if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP)
  195.             {
  196.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_Esc) //esc
  197.                 {
  198.                     INPUT[] inputs = new INPUT[] {
  199.                         INPUT.VirtualKeyUp((ushort)0x01),
  200.                     };
  201.                     returnMe = 1;
  202.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  203.                 }
  204.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_LShift) //ice
  205.                 {
  206.                     INPUT[] inputs = new INPUT[] {
  207.                         INPUT.VirtualKeyUp((ushort)0x2a),
  208.                     };
  209.                     returnMe = 1;
  210.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  211.                 }
  212.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_Space) //fire
  213.                 {
  214.                     INPUT[] inputs = new INPUT[] {
  215.                         INPUT.VirtualKeyUp((ushort)0x39),
  216.                     };
  217.                     returnMe = 1;
  218.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  219.                 }
  220.                 // MessageBox.Show(((System.Windows.Forms.Keys)vkCode).ToString());
  221.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_LClick) //fire
  222.                 {
  223.                     const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
  224.                     const uint MOUSEEVENTF_LEFTUP = 0x0004;
  225.                     //mouse_event(MOUSEEVENTF_LEFTDOWN, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
  226.                     mouse_event(MOUSEEVENTF_LEFTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
  227.  
  228.                 }
  229.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_RClick) //fire
  230.                 {
  231.                     const uint RIGHTDOWN = 0x0008;
  232.                     const uint RIGHTUP = 0x0010;
  233.                     //mouse_event(RIGHTDOWN, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
  234.                     mouse_event(RIGHTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
  235.  
  236.                 }
  237.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_W)
  238.                 {
  239.                    
  240.                     INPUT[] inputs = new INPUT[] {
  241.                         INPUT.VirtualKeyUp((ushort)0x11),                              
  242.                     };
  243.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  244.                     returnMe = 1;
  245.                 }
  246.                 else if (((System.Windows.Forms.Keys)vkCode).ToString() == key_S)
  247.                 {
  248.                     INPUT[] inputs = new INPUT[] {
  249.                         INPUT.VirtualKeyUp((ushort)0x1f),
  250.                     };
  251.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  252.                     returnMe = 1;
  253.                 }
  254.                 else if (((System.Windows.Forms.Keys)vkCode).ToString() == key_D)
  255.                 {
  256.                     INPUT[] inputs = new INPUT[] {
  257.                         INPUT.VirtualKeyUp((ushort)0x20),
  258.                     };
  259.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  260.                     returnMe = 1;
  261.                 }
  262.                 else if (((System.Windows.Forms.Keys)vkCode).ToString() == key_A)
  263.                 {
  264.                     INPUT[] inputs = new INPUT[] {
  265.                         INPUT.VirtualKeyUp((ushort)0x1e),
  266.                     };
  267.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  268.                     returnMe = 1;
  269.                 }
  270.             }
  271.             if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
  272.             {
  273.                 //f5,6,7 is F, Q, E
  274.                
  275.                
  276.                 //MessageBox.Show(((System.Windows.Forms.Keys)vkCode).ToString());
  277.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_Esc) //esc
  278.                 {
  279.                     INPUT[] inputs = new INPUT[] {
  280.                         INPUT.VirtualKeyDown((ushort)0x01),
  281.                     };
  282.                     returnMe = 1;
  283.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  284.                 }
  285.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_F) //F
  286.                 {
  287.                     INPUT[] inputs = new INPUT[] {
  288.                         INPUT.VirtualKeyDown((ushort)0x21),
  289.                     };
  290.                     returnMe = 1;
  291.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  292.                 }
  293.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_Q) //Q
  294.                 {
  295.                     INPUT[] inputs = new INPUT[] {
  296.                         INPUT.VirtualKeyDown((ushort)0x10),
  297.                     };
  298.                     returnMe = 1;
  299.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  300.                 }
  301.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_E) //E
  302.                 {
  303.                     INPUT[] inputs = new INPUT[] {
  304.                         INPUT.VirtualKeyDown((ushort)0x12),
  305.                     };
  306.                     returnMe = 1;
  307.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  308.                 }
  309.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_LShift) //ice
  310.                 {
  311.                     INPUT[] inputs = new INPUT[] {
  312.                         INPUT.VirtualKeyDown((ushort)0x2a),
  313.                     };
  314.                     returnMe = 1;
  315.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  316.                 }
  317.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_Space) //fire
  318.                 {
  319.                     INPUT[] inputs = new INPUT[] {
  320.                         INPUT.VirtualKeyDown((ushort)0x39),
  321.                     };
  322.                     returnMe = 1;
  323.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  324.                 }
  325.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_LClick) //spell
  326.                 {
  327.                     const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
  328.                     const uint MOUSEEVENTF_LEFTUP = 0x0004;
  329.                     mouse_event(MOUSEEVENTF_LEFTDOWN, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
  330.                     //mouse_event(MOUSEEVENTF_LEFTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
  331.  
  332.                 }
  333.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_RClick) //ligghtning
  334.                 {
  335.                    const uint RIGHTDOWN  = 0x0008;
  336.                    const uint RIGHTUP = 0x0010;
  337.                    mouse_event(RIGHTDOWN, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
  338.                   // mouse_event(RIGHTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
  339.  
  340.                 }
  341.                 if (((System.Windows.Forms.Keys)vkCode).ToString() == key_W)
  342.                 {
  343.                    
  344.                     Keys myKey = new Keys();
  345.                     //Keys.LButton;
  346.                     myKey = Keys.D;
  347.                     Keys myKey2 = new Keys();
  348.                     myKey2 = Keys.A;
  349.                     Keys myKey3 = new Keys();
  350.                    
  351.                     myKey3 = Keys.LButton;
  352.                     if (!IsKeyDown(myKey3))
  353.                     {
  354.                         if (IsKeyDown(myKey))
  355.                         {
  356.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  357.                             int screenWidth = resolution_Width;
  358.                             int screenHeight = 0;// resolution_Height;
  359.                             Win32.POINT p = new Win32.POINT();
  360.                             p.x = Convert.ToInt16(screenWidth);
  361.                             p.y = Convert.ToInt16(screenHeight);
  362.  
  363.                             //Win32.ClientToScreen(moduleHandle, ref p);
  364.                             Win32.SetCursorPos(p.x, p.y);
  365.                         }
  366.                         else if (IsKeyDown(myKey2))
  367.                         {
  368.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  369.                             int screenWidth = 0;
  370.                             int screenHeight = 0;// resolution_Height;
  371.                             Win32.POINT p = new Win32.POINT();
  372.                             p.x = Convert.ToInt16(screenWidth);
  373.                             p.y = Convert.ToInt16(screenHeight);
  374.  
  375.                             //Win32.ClientToScreen(moduleHandle, ref p);
  376.                             Win32.SetCursorPos(p.x, p.y);
  377.                         }
  378.                         else
  379.                         {
  380.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  381.                             int screenWidth = resolution_Width / 2;
  382.                             int screenHeight = 0;// resolution_Height;
  383.                             Win32.POINT p = new Win32.POINT();
  384.                             p.x = Convert.ToInt16(screenWidth);
  385.                             p.y = Convert.ToInt16(screenHeight);
  386.  
  387.                             //Win32.ClientToScreen(moduleHandle, ref p);
  388.                             Win32.SetCursorPos(p.x, p.y);
  389.                         }
  390.                     }
  391.                     INPUT[] inputs = new INPUT[] {
  392.                         INPUT.VirtualKeyDown((ushort)0x11),
  393.                     };
  394.                     returnMe = 1;
  395.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  396.                 }
  397.                 else if (((System.Windows.Forms.Keys)vkCode).ToString() == key_S) //down
  398.                 {
  399.                      Keys myKey = new Keys();
  400.                     myKey = Keys.A;
  401.                     Keys myKey2 = new Keys();
  402.                     myKey2 = Keys.D;
  403.                     Keys myKey3 = new Keys();
  404.                     myKey3 = Keys.LButton;
  405.                     if (!IsKeyDown(myKey3))
  406.                     {
  407.                         if (IsKeyDown(myKey))
  408.                         {
  409.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  410.                             int screenWidth = 0;
  411.                             int screenHeight = resolution_Height;// resolution_Height;
  412.                             Win32.POINT p = new Win32.POINT();
  413.                             p.x = Convert.ToInt16(screenWidth);
  414.                             p.y = Convert.ToInt16(screenHeight);
  415.  
  416.                             //Win32.ClientToScreen(moduleHandle, ref p);
  417.                             Win32.SetCursorPos(p.x, p.y);
  418.                         }
  419.                         else if (IsKeyDown(myKey2))
  420.                         {
  421.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  422.                             int screenWidth = resolution_Width;
  423.                             int screenHeight = resolution_Height;// resolution_Height;
  424.                             Win32.POINT p = new Win32.POINT();
  425.                             p.x = Convert.ToInt16(screenWidth);
  426.                             p.y = Convert.ToInt16(screenHeight);
  427.  
  428.                             //Win32.ClientToScreen(moduleHandle, ref p);
  429.                             Win32.SetCursorPos(p.x, p.y);
  430.                         }
  431.                         else
  432.                         {
  433.                             int screenWidth = resolution_Width / 2; //resolution_Width
  434.                             int screenHeight = resolution_Height;// resolution_Height;
  435.  
  436.                             Win32.POINT p = new Win32.POINT();
  437.                             p.x = Convert.ToInt16(screenWidth);
  438.                             p.y = Convert.ToInt16(screenHeight);
  439.                             Win32.SetCursorPos(p.x, p.y);
  440.                         }
  441.                     }
  442.                     INPUT[] inputs = new INPUT[] {
  443.                         INPUT.VirtualKeyDown((ushort)0x1f),
  444.                     };
  445.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  446.                     returnMe = 1;
  447.                 }
  448.                 else if (((System.Windows.Forms.Keys)vkCode).ToString() == key_D)//right
  449.                 {
  450.                     Keys myKey = new Keys();
  451.                     myKey = Keys.W;
  452.                     Keys myKey2 = new Keys();
  453.                     myKey2 = Keys.S;
  454.                     Keys myKey3 = new Keys();
  455.                     myKey3 = Keys.LButton;
  456.                     if (!IsKeyDown(myKey3))
  457.                     {
  458.                         if (IsKeyDown(myKey))
  459.                         {
  460.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  461.                             int screenWidth = resolution_Width;
  462.                             int screenHeight = 0;// resolution_Height;
  463.                             Win32.POINT p = new Win32.POINT();
  464.                             p.x = Convert.ToInt16(screenWidth);
  465.                             p.y = Convert.ToInt16(screenHeight);
  466.  
  467.                             //Win32.ClientToScreen(moduleHandle, ref p);
  468.                             Win32.SetCursorPos(p.x, p.y);
  469.                         }
  470.                         else if (IsKeyDown(myKey2))
  471.                         {
  472.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  473.                             int screenWidth = resolution_Width;
  474.                             int screenHeight = resolution_Height;// resolution_Height;
  475.                             Win32.POINT p = new Win32.POINT();
  476.                             p.x = Convert.ToInt16(screenWidth);
  477.                             p.y = Convert.ToInt16(screenHeight);
  478.  
  479.                             //Win32.ClientToScreen(moduleHandle, ref p);
  480.                             Win32.SetCursorPos(p.x, p.y);
  481.                         }
  482.  
  483.                         else
  484.                         {
  485.                             int screenWidth = resolution_Width; //resolution_Width
  486.                             int screenHeight = resolution_Height / 2;// resolution_Height;
  487.                             Win32.POINT p = new Win32.POINT();
  488.                             p.x = Convert.ToInt16(screenWidth);
  489.                             p.y = Convert.ToInt16(screenHeight);
  490.                             Win32.SetCursorPos(p.x, p.y);
  491.                         }
  492.                     }
  493.                     INPUT[] inputs = new INPUT[] {
  494.                         INPUT.VirtualKeyDown((ushort)0x20),
  495.                     };
  496.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  497.                     returnMe = 1;
  498.                 }
  499.                 else if (((System.Windows.Forms.Keys)vkCode).ToString() == key_A)
  500.                 {
  501.                      Keys myKey = new Keys();
  502.                     myKey = Keys.W;
  503.                     Keys myKey2 = new Keys();
  504.                     myKey2 = Keys.S;
  505.                     Keys myKey3 = new Keys();
  506.                     myKey3 = Keys.LButton;
  507.                     if (!IsKeyDown(myKey3))
  508.                     {
  509.                         if (IsKeyDown(myKey))
  510.                         {
  511.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  512.                             int screenWidth = 0;
  513.                             int screenHeight = 0;// resolution_Height;
  514.                             Win32.POINT p = new Win32.POINT();
  515.                             p.x = Convert.ToInt16(screenWidth);
  516.                             p.y = Convert.ToInt16(screenHeight);
  517.  
  518.                             //Win32.ClientToScreen(moduleHandle, ref p);
  519.                             Win32.SetCursorPos(p.x, p.y);
  520.                         }
  521.                         else if (IsKeyDown(myKey2))
  522.                         {
  523.                             //System.Windows.Input.Keyboard.GetKeyStates(Key.Q));
  524.                             int screenWidth = 0;
  525.                             int screenHeight = resolution_Height;// resolution_Height;
  526.                             Win32.POINT p = new Win32.POINT();
  527.                             p.x = Convert.ToInt16(screenWidth);
  528.                             p.y = Convert.ToInt16(screenHeight);
  529.  
  530.                             //Win32.ClientToScreen(moduleHandle, ref p);
  531.                             Win32.SetCursorPos(p.x, p.y);
  532.                         }
  533.                         else
  534.                         {
  535.                             int screenWidth = 0; //resolution_Width
  536.                             int screenHeight = resolution_Height / 2;// resolution_Height;
  537.                             Win32.POINT p = new Win32.POINT();
  538.                             p.x = Convert.ToInt16(screenWidth);
  539.                             p.y = Convert.ToInt16(screenHeight);
  540.                             Win32.SetCursorPos(p.x, p.y);
  541.                         }
  542.                     }
  543.                     INPUT[] inputs = new INPUT[] {
  544.                         INPUT.VirtualKeyDown((ushort)0x1e),
  545.                     };
  546.                     SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
  547.                     returnMe = 1;
  548.                 }
  549.             }
  550.             if (returnMe == (int)1)
  551.             {
  552.                 return (System.IntPtr)1;
  553.             }
  554.             else
  555.             {
  556.                 return CallNextHookEx(hookId, nCode, wParam, lParam);
  557.             }
  558.  
  559.         }
  560.         /***********************************************************
  561.          *
  562.          *                      Keyboard Input
  563.          *
  564.          *
  565.          * *********************************************************/
  566.         private enum INPUTTYPE : uint
  567.         {
  568.             Keyboard = 1
  569.         }
  570.  
  571.         private enum KEYEVENTF : uint
  572.         {
  573.             KeyUp = 2,
  574.             Scan = 8,
  575.         }
  576.  
  577.         [DllImport("User32.dll", SetLastError = true)]
  578.         private static extern uint SendInput(int nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] inputs, int cbSize);
  579.  
  580.         [StructLayout(LayoutKind.Sequential)]
  581.         private struct INPUT
  582.         {
  583.             public INPUTTYPE type;
  584.             public INPUT_U u;
  585.  
  586.             public static INPUT VirtualKeyDown(ushort keyP)
  587.             {
  588.  
  589.                 var input = new INPUT() { type = INPUTTYPE.Keyboard };
  590.  
  591.  
  592.                 input.u.ki = new KEYBDINPUT() { scanCode = (ushort)keyP, flags = (KEYEVENTF)0x0008 };
  593.  
  594.                 return input;
  595.             }
  596.            
  597.             public static INPUT VirtualKeyUp(ushort keyP)
  598.             {
  599.                 var input = new INPUT() { type = INPUTTYPE.Keyboard };
  600.                 input.u.ki = new KEYBDINPUT() { scanCode = (ushort)keyP, flags = (KEYEVENTF)0x0008 | (KEYEVENTF)0x0002 };
  601.  
  602.                 return input;
  603.             }
  604.         }
  605.  
  606.         [StructLayout(LayoutKind.Explicit)]
  607.         private struct INPUT_U
  608.         {
  609.             [FieldOffset(0)]
  610.             public KEYBDINPUT ki;
  611.  
  612.             [FieldOffset(0)]
  613.             public MOUSEINPUT mi;
  614.  
  615.             [FieldOffset(0)]
  616.             public HARDWAREINPUT hi;
  617.         }
  618.  
  619.         [StructLayout(LayoutKind.Sequential)]
  620.         private struct KEYBDINPUT
  621.         {
  622.             public ushort virtualKey;
  623.             public ushort scanCode;
  624.             public KEYEVENTF flags;
  625.             public uint time;
  626.  
  627.             public IntPtr extraInfo;
  628.         }
  629.  
  630.         [StructLayout(LayoutKind.Sequential)]
  631.         private struct MOUSEINPUT
  632.         {
  633.             public int dx;
  634.             public int dy;
  635.             public uint mouseData;
  636.             public uint flags;
  637.             public uint time;
  638.             public IntPtr extraInfo;
  639.         }
  640.  
  641.         [StructLayout(LayoutKind.Sequential)]
  642.         private struct HARDWAREINPUT
  643.         {
  644.             public int uMsg;
  645.             public IntPtr wParam;
  646.             public IntPtr lParam;
  647.         }
  648.  
  649.         private void textBox1_TextChanged(object sender, EventArgs e)
  650.         {
  651.  
  652.         }
  653.  
  654.         private void textBox1_MouseDown(object sender, MouseEventArgs e)
  655.         {
  656.  
  657.         }
  658.  
  659.         private void textBox1_KeyDown(object sender, KeyEventArgs e)
  660.         {
  661.             // Key currentKey = new Key();
  662.            
  663.         }
  664.     }
  665. }
Advertisement
Add Comment
Please, Sign In to add comment