Exemple #1
0
        /// <summary>
        /// Immediately release a key, by sending a keyup event to the game.
        /// </summary>
        /// <param name="key">The scan code (NOT the VK_ keycode!) of the key to release.</param>
        public void Keyup(ScanCode key)
        {
            lock (pressed_keys)
            {
                if (!pressed_keys.Contains(key))
                {
                    return;
                }

                pressed_keys.Remove(key);
            }
            SendInputWrapper.SendInput(new INPUT
            {
                Type = (uint)InputType.Keyboard,
                Data =
                {
                    Keyboard      = new KEYBDINPUT
                    {
                        Vk        =                                                      0,
                        Scan      = (ushort)key,
                        Flags     = (uint)KeyboardFlag.ScanCode | (uint)KeyboardFlag.KeyUp,
                        Time      =                                                      0,
                        ExtraInfo = IntPtr.Zero
                    }
                }
            });
        }
Exemple #2
0
 private static void SendInput(ICollection <SendInputWrapper.INPUT> inputList)
 {
     SendInputWrapper.SendInput(
         (uint)inputList.Count,
         inputList.ToArray(),
         Marshal.SizeOf(typeof(SendInputWrapper.INPUT)));
 }
Exemple #3
0
        // Set cursor position relative
        public static bool SetPositionRelative(int cDeltaX,
                                               int cDeltaY)
        {
            // Create INPUT structure
            var input = new SendInputWrapper.Input();

            // Fill it
            input.mType = SendInputWrapper.eInputTypes.INPUT_MOUSE;
            input.mData.mMi.mMouseData = 0;
            input.mData.mMi.mTime      = 0;
            input.mData.mMi.mX         = cDeltaX;
            input.mData.mMi.mY         = cDeltaY;
            input.mData.mMi.mFlags     = SendInputWrapper.eMouseEventFlags.MOUSEEVENTF_MOVE;
            // Send input
            return(SendInputWrapper.SendInput(input));
        }
Exemple #4
0
 /// <summary>
 /// Move the mouse. Takes doubles for convenience.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public void MouseMoveRelative(double x, double y)
 {
     SendInputWrapper.SendInput(new INPUT
     {
         Type = (uint)InputType.Mouse,
         Data =
         {
             Mouse         = new MOUSEINPUT
             {
                 X         = (int)x,
                 Y         = (int)y,
                 MouseData =            0,
                 Flags     =            0,
                 Time      =            0,
                 ExtraInfo = (IntPtr)null,
             }
         }
     });
 }
Exemple #5
0
        // Set cursor position absolute
        public static bool SetPositionAbsolute(CursorPosition cPos)
        {
            // Get resolution
            var res_info = DesktopHelper.GetResolution();

            // Absolute coordinates are from 0 to 65536
            int real_x = (cPos.X * 65536) / res_info.Width;
            int real_y = (cPos.Y * 65536) / res_info.Height;

            // Create INPUT structure
            var input = new SendInputWrapper.Input();

            // Fill it
            input.mType = SendInputWrapper.eInputTypes.INPUT_MOUSE;
            input.mData.mMi.mMouseData = 0;
            input.mData.mMi.mTime      = 0;
            input.mData.mMi.mX         = real_x;
            input.mData.mMi.mY         = real_y;
            input.mData.mMi.mFlags     = SendInputWrapper.eMouseEventFlags.MOUSEEVENTF_ABSOLUTE | SendInputWrapper.eMouseEventFlags.MOUSEEVENTF_MOVE;
            // Send input
            return(SendInputWrapper.SendInput(input));
        }
Exemple #6
0
        /// <summary>
        /// Start pressing down on a key. Sends a "keydown" event to the game.
        /// </summary>
        /// <param name="key">The scan code (NOT the VK_ keycode!) of the key to press.</param>
        public void Keydown(ScanCode key)
        {
            lock (pressed_keys)
            {
                if (pressed_keys.Contains(key))
                {
                    return;
                }

                pressed_keys.Add(key);
            }

            // program doesn't recognize this..
            // PostMessage(hWnd, WM_KEYDOWN, ((IntPtr)key), (IntPtr)0);

            // need to use sendinput instead
            // this means the target program must be the foreground window :(

            // program also doesn't recognize virtual key codes for anything except text chat..

            SendInputWrapper.SendInput(new INPUT
            {
                Type = (uint)InputType.Keyboard,
                Data =
                {
                    Keyboard      = new KEYBDINPUT
                    {
                        Vk        =                           0,
                        Scan      = (ushort)key,
                        Flags     = (uint)KeyboardFlag.ScanCode,
                        Time      =                           0,
                        ExtraInfo = IntPtr.Zero
                    }
                }
            });
        }
Exemple #7
0
        /// <summary>
        /// Invoca el SendInput de SendInputWrapper para que se ejecute
        /// la pulsación correspondiente <see cref="KeystrokeType"/> de la
        /// tecla correspondiente <see cref="Key"/>
        /// </summary>
        public void ExecuteKeystroke()
        {
            SendInputWrapper sendInput = new SendInputWrapper();

            sendInput.SendInput(this);
        }