Ejemplo n.º 1
0
        public async Task SendWindowModeCommandAsync()
        {
            bool    isFullScreen           = _windowModeMonitor.IsForegroundFullScreen();
            Process leagueOfLegendsProcess = Process.GetProcessesByName(LeagueClientProcess).First();

            bool isCurrentFullScreen = isFullScreen;

            do
            {
                await Task.Run(async() =>
                {
                    SetForegroundWindow(leagueOfLegendsProcess.MainWindowHandle);
                    if (isCurrentFullScreen)
                    {
                        await Task.Delay(5000);
                    }

                    //simulate double-keypress
                    SendInputWrapper.SendKey(_initializerToUShortMapper.Map(Initializer.Alt), press: true);
                    await Task.Delay(10);
                    SendInputWrapper.SendKey(_initializerToUShortMapper.Map(Initializer.Enter), press: true);
                    await Task.Delay(10);
                    SendInputWrapper.SendKey(_initializerToUShortMapper.Map(Initializer.Enter), press: false);
                    await Task.Delay(10);;
                    SendInputWrapper.SendKey(_initializerToUShortMapper.Map(Initializer.Alt), press: false);
                    await Task.Delay(3000);

                    isCurrentFullScreen = _windowModeMonitor.IsForegroundFullScreen();
                });
            } while (isCurrentFullScreen == isFullScreen);
        }
Ejemplo n.º 2
0
 private static void SendInput(ICollection <SendInputWrapper.INPUT> inputList)
 {
     SendInputWrapper.SendInput(
         (uint)inputList.Count,
         inputList.ToArray(),
         Marshal.SizeOf(typeof(SendInputWrapper.INPUT)));
 }
Ejemplo n.º 3
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
                    }
                }
            });
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public void SetKeybind(string key)
        {
            var keybindOld = Keybind;

            try
            {
                Keybind = key.ToCharArray()[0].ToString().ToUpper();

                // http://www.pinvoke.net/default.aspx/user32/MapVirtualKey.html
                _VirtualKeyCode = (SendInputWrapper.ScanCodeShort)SendInputWrapper.MapVirtualKey((uint)(Keys)Enum.Parse(typeof(Keys), _Keybind, true), 0x00);
                log.Info("Changed keybind to " + Keybind);
            }
            catch (Exception e)
            {
                log.Debug("Unable to set keybind: " + e.Message);
                Keybind = keybindOld;
            }
        }
Ejemplo n.º 6
0
        public async Task SendKeystrokeAsync(Initializer initialzer)
        {
            var     directInputKeyScan     = _initializerToUShortMapper.Map(initialzer);
            Process leagueOfLegendsProcess = Process.GetProcessesByName(LeagueClientProcess).First();
            var     recordingProcessHandle = Process.GetCurrentProcess().MainWindowHandle;

            IntPtr foregroundWindow = IntPtr.Zero;

            do
            {
                await Task.Run(async() =>
                {
                    for (int i = 1; i < 10; i++)
                    {
                        WindowModeMonitor.WINDOWPLACEMENT processWindowState = _windowModeMonitor.GetPlacement(leagueOfLegendsProcess.MainWindowHandle);
                        if (processWindowState.showCmd == WindowModeMonitor.ShowWindowCommands.Minimized)
                        {
                            if (!leagueOfLegendsProcess.Responding)
                            {
                                throw new LeagueOfLegendsProcessException($"League Client is not responding. ");
                            }
                            ShowWindow(leagueOfLegendsProcess.MainWindowHandle, VM_RESTORE);
                            await Task.Delay(5000);
                        }
                        else
                        {
                            SetForegroundWindow(leagueOfLegendsProcess.MainWindowHandle);
                        }

                        //simulate double-keypress
                        SendInputWrapper.SendKey(directInputKeyScan, press: true);
                        await Task.Delay(10);
                        SendInputWrapper.SendKey(directInputKeyScan, press: false);
                        await Task.Delay(10);
                        SendInputWrapper.SendKey(directInputKeyScan, press: true);
                        await Task.Delay(10);
                        SendInputWrapper.SendKey(directInputKeyScan, press: false);
                        await Task.Delay(10);

                        foregroundWindow = GetForegroundWindow();
                    }
                });
            } while (foregroundWindow != leagueOfLegendsProcess.MainWindowHandle);
        }
Ejemplo n.º 7
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,
             }
         }
     });
 }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        public static byte[] manipulateMouse(Command command)
        {
            MouseRequest     request = (MouseRequest)Util.Serialization.deserialize(command.data);
            Screen           screen  = Screen.AllScreens[request.monitorIndex];
            SendInputWrapper wrapper = new SendInputWrapper();
            double           x       = (lerp(0, screen.Bounds.Width - 1, request.x / request.ax));
            double           y       = (lerp(0, screen.Bounds.Height - 1, request.y / request.ay));

            wrapper.sim_mov((int)(((screen.Bounds.X + x) / 2.0)), (int)(((screen.Bounds.Y + y) / 2.0)));
            if (request.isClick)
            {
                if (request.isRightClick)
                {
                    wrapper.sim_right_click();
                }
                else
                {
                    wrapper.sim_left_click();
                }
            }
            return(new byte[] { });
        }
        private void internalTriggerControl(Control ctl, ControlType cType, ControlTriggerType cTrigType)
        {
            if (ctl == null)
            {
                throw new ApplicationException("internalTriggerControl cannot trigger a null control in test: " + this.testName);
            }

            Cursor.Position =
                new Point(ctl.Location.X + (ctl.Bounds.Width / 2), ctl.Location.Y + (ctl.Bounds.Height / 2));
            SendInputWrapper.Click();

/*            switch (cType)
 *          {
 *              case ControlType.UNKNOWN:
 *                  break;
 *              case ControlType.UNKNOWN_XY:
 *                  Cursor.Position =
 *                      new Point(ctl.Location.X + (ctl.Bounds.Width / 2), ctl.Location.Y + (ctl.Bounds.Height / 2));
 *                  SendInputWrapper.Click();
 *                  break;
 *              case ControlType.TEXTBOX:
 *                  break;
 *              case ControlType.BUTTON:
 *                  break;
 *              case ControlType.LISTBOX:
 *                  break;
 *              case ControlType.COMBOBOX:
 *                  break;
 *              case ControlType.AUTOCOMPLETE:
 *                  break;
 *              case ControlType.DATAGRIDROW:
 *                  break;
 *              case ControlType.DATAGRIDROWCOLUMN:
 *                  break;
 *              default:
 *                  throw new ArgumentOutOfRangeException("cType");
 *          }*/
        }
Ejemplo n.º 11
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
                    }
                }
            });
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
 private static List<SendInputWrapper.INPUT> AddKeybdInput(
     List<SendInputWrapper.INPUT> inputs,
     byte vk,
     SendInputWrapper.KEYEVENTF dwFlags)
 {
     if (null == inputs)
     {
         inputs = new List<SendInputWrapper.INPUT>();
     }
     inputs.Add(MakeKeybdInput(vk, dwFlags));
     return inputs;
 }
Ejemplo n.º 14
0
 private static List<SendInputWrapper.INPUT> AddInput(
     List<SendInputWrapper.INPUT> inputs,
     SendInputWrapper.INPUT newInput)
 {
     if (null == inputs)
     {
         inputs = new List<SendInputWrapper.INPUT>();
     }
     inputs.Add(newInput);
     return inputs;
 }
Ejemplo n.º 15
0
 private static SendInputWrapper.INPUT MakeKeybdInput(byte vk, SendInputWrapper.KEYEVENTF dwFlags)
 {
     return new SendInputWrapper.INPUT
     {
         type = SendInputWrapper.INPUT_KEYBOARD,
         u = new SendInputWrapper.InputUnion
         {
             ki = new SendInputWrapper.KEYBDINPUT
             {
                 wVk = vk,
                 wScan = 0,
                 dwFlags = dwFlags,
             }
         }
     };
 }
Ejemplo n.º 16
0
        public void Update()
        {
            if (_State.Speed > _ThreshRun && !_UserIsRunning)
            {
                SendInputWrapper.KeyDown(_VirtualKeyCode);
                //KbM.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.VK_W);
                UserIsRunning = true;
            }
            else if (_State.Speed <= _ThreshRun && UserIsRunning)
            {
                SendInputWrapper.KeyUp(_VirtualKeyCode);
                //KbM.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.VK_W);
                UserIsRunning = false;
            }

            if (false) // TODO: Implement jumping on iPhone
            {
                _KbM.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.SPACE);
            }

            if ((_State.Buttons & PocketStrafeButtons.ButtonA) != 0 & !_LeftMouseButtonDown) // A button pressed on phone
            {
                _KbM.Mouse.LeftButtonDown();
                _LeftMouseButtonDown = true;
            }
            if ((_State.Buttons & PocketStrafeButtons.ButtonA) == 0 & _LeftMouseButtonDown)
            {
                _KbM.Mouse.LeftButtonUp();
                _LeftMouseButtonDown = false;
            }

            if ((_State.Buttons & PocketStrafeButtons.ButtonB) != 0 & !_RightMouseButtonDown) // B button pressed on phone
            {
                _KbM.Mouse.RightButtonDown();
                _RightMouseButtonDown = true;
            }
            if ((_State.Buttons & PocketStrafeButtons.ButtonB) == 0 & _RightMouseButtonDown)
            {
                _KbM.Mouse.RightButtonUp();
                _RightMouseButtonDown = false;
            }

            if ((_State.Buttons & PocketStrafeButtons.ButtonUp) != 0 & !_UpButtonPressed) // Up-arrow pressed on phone
            {
                SendInputWrapper.KeyDown(GetScanCode(Keys.Up));
                _UpButtonPressed = true;
            }
            else if ((_State.Buttons & PocketStrafeButtons.ButtonUp) == 0 & _UpButtonPressed)
            {
                SendInputWrapper.KeyUp(GetScanCode(Keys.Up));
                _UpButtonPressed = false;
            }

            if ((_State.Buttons & PocketStrafeButtons.ButtonDown) != 0 & !_DownButtonPressed) // Down-arrow pressed on phone
            {
                SendInputWrapper.KeyDown(GetScanCode(Keys.Down));
                _DownButtonPressed = true;
            }
            else if ((_State.Buttons & PocketStrafeButtons.ButtonDown) == 0 & _DownButtonPressed)
            {
                SendInputWrapper.KeyUp(GetScanCode(Keys.Down));
                _DownButtonPressed = false;
            }

            if ((_State.Buttons & PocketStrafeButtons.ButtonLeft) != 0 && !_LeftButtonPressed) // Left-arrow pressed on phone
            {
                SendInputWrapper.KeyDown(GetScanCode(Keys.Left));
                _LeftButtonPressed = true;
            }
            else if ((_State.Buttons & PocketStrafeButtons.ButtonLeft) == 0 && _LeftButtonPressed)
            {
                SendInputWrapper.KeyUp(GetScanCode(Keys.Left));
                _LeftButtonPressed = false;
            }

            if ((_State.Buttons & PocketStrafeButtons.ButtonRight) != 0 && !_RightButtonPressed) // Right-arrow pressed on phone
            {
                SendInputWrapper.KeyDown(GetScanCode(Keys.Right));
                _RightButtonPressed = true;
            }
            else if ((_State.Buttons & PocketStrafeButtons.ButtonRight) == 0 && _RightButtonPressed)
            {
                SendInputWrapper.KeyUp(GetScanCode(Keys.Right));
                _RightButtonPressed = false;
            }

            ResetState();
        }
Ejemplo n.º 17
0
 private SendInputWrapper.ScanCodeShort GetScanCode(Keys key)
 {
     return((SendInputWrapper.ScanCodeShort)SendInputWrapper.MapVirtualKey((uint)key, 0x00));
 }