コード例 #1
0
ファイル: Win32.cs プロジェクト: willrawls/arp
        public static void SendEscape(IntPtr target)
        {
            if(target != IntPtr.Zero)
            {
                int processId;
                int inputThread = Win32Declarations.GetWindowThreadProcessId(target, out processId);
                Assert.Check(inputThread == Win32Declarations.GetCurrentThreadId());
            }

            INPUT[] input = new INPUT[2];
            input[0].type = input[1].type = Win32Declarations.INPUT_KEYBOARD;
            input[0].ki.wScan = input[1].ki.wScan = 0;
            input[0].ki.time = input[1].ki.time = 0;
            input[1].ki.dwFlags = Win32Declarations.KEYEVENTF_KEYUP;
            input[0].ki.dwExtraInfo = input[1].ki.dwExtraInfo = GetMessageExtraInfo();
            input[0].ki.wVk = input[1].ki.wVk = 0x1B; // escape

            uint ret = Win32Declarations.SendInput(input);

            if(ret != 2)
            {
                throw new Win32Exception("Unexpected error " + Win32Declarations.GetLastError());
            }

            // TODO use SetForegroundWindow ?
        }
コード例 #2
0
ファイル: KeyEvent.cs プロジェクト: KeyMove/MJpegServer
        public static void MouseSend(int x, int y, Input.MouseFlag flag, int data)
        {
            INPUT[] input = new INPUT[1];
            int value = (int)flag;
            if (flag == Input.MouseFlag.MoveTo)
            {
                value = ((int)(MOUSEEVENTF_ABSOLUTE) | (int)(MOUSEEVENTF_MOVE));
                x = 65536 * x / W;
                y = 65536 * y / H;
            }
            if (flag == Input.MouseFlag.AddTo)
            {
                x = 65536 * x / W;
                y = 65536 * y / H;
            }
            input[0] = new INPUT();
            input[0].mi.dx = x;
            input[0].mi.dy = y;
            input[0].mi.dwExtraInfo = (IntPtr)0;
            input[0].mi.time = 0;
            input[0].mi.mouseData = data;

            input[0].mi.dwFlags = value;
            input[0].type = INPUT_MOUSE;
            SendInput(1, input, Marshal.SizeOf(input[0]));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: NoahPena/Mouse_Glove
 public static void LeftMouseButtonUp()
 {
     INPUT mouseUpInput = new INPUT();
     mouseUpInput.type = SendInputEventType.InputMouse;
     mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
     SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
 }
コード例 #4
0
ファイル: KEYBDControl.cs プロジェクト: pstegegn/RMOE
        public static void pressKey(ushort key)
        {
            INPUT[] InputList = new INPUT[2];

            InputList[0] = new INPUT();
            InputList[0].type = 1;

            //Keys virtualKeycode = (Keys)0x15;

            InputList[0].ki.wVk = key;
            InputList[0].ki.wScan = 0;
            InputList[0].ki.time = 0;
            InputList[0].ki.dwFlags = 0;
            InputList[0].ki.dwExtraInfo = (uint)IntPtr.Zero;

            InputList[1] = new INPUT();
            InputList[1].type = 1;

            //Keys virtualKeycode = (Keys)0x15;

            InputList[1].ki.wVk = key;
            InputList[1].ki.wScan = 0;
            InputList[1].ki.time = 0;
            InputList[1].ki.dwFlags = 2;
            InputList[1].ki.dwExtraInfo = (uint)IntPtr.Zero;

            // keyInput.ki.dwFlags = (int)KeyEvent.KeyUp;

            // InputList[1] = keyInput;

            uint stat = SendInput((uint)2, InputList, Marshal.SizeOf(InputList[0]));
            Console.WriteLine("\nresult {0} , ", stat);
        }
コード例 #5
0
        private static void DoClickMouse(ClickNodeSubType clickType)
        {
            INPUT mouseInput = new INPUT()
            {
                type = 0, // Mouse input
                mi = new MOUSEINPUT()
            };

            switch(clickType)
            {
                case ClickNodeSubType.LeftClick:
                    mouseInput.mi.dwFlags = MouseEventFlags.LeftDown;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    mouseInput.mi.dwFlags = MouseEventFlags.LeftUp;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    break;

                case ClickNodeSubType.RightClick:
                    mouseInput.mi.dwFlags = MouseEventFlags.RightDown;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    mouseInput.mi.dwFlags = MouseEventFlags.RightUp;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    break;

                case ClickNodeSubType.MiddleClick:
                    mouseInput.mi.dwFlags = MouseEventFlags.MiddleDown;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    mouseInput.mi.dwFlags = MouseEventFlags.MiddleUp;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    break;
            }
        }
コード例 #6
0
ファイル: MouseController.cs プロジェクト: Xunnamius/GBotGUI
        public static void DoClickMouse(ClickRecordType clickType)
        {
            INPUT mouseInput = new INPUT()
            {
                type = 0, // Mouse input
                mi = new MOUSEINPUT()
            };

            switch(clickType)
            {
                case ClickRecordType.LeftClick:
                    mouseInput.mi.dwFlags = MouseEventFlags.LeftDown;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    System.Threading.Thread.Sleep(150);
                    mouseInput.mi.dwFlags = MouseEventFlags.LeftUp;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    break;

                case ClickRecordType.RightClick:
                    mouseInput.mi.dwFlags = MouseEventFlags.RightDown;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    System.Threading.Thread.Sleep(150);
                    mouseInput.mi.dwFlags = MouseEventFlags.RightUp;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    break;

                case ClickRecordType.MiddleClick:
                    mouseInput.mi.dwFlags = MouseEventFlags.MiddleDown;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    System.Threading.Thread.Sleep(150);
                    mouseInput.mi.dwFlags = MouseEventFlags.MiddleUp;
                    SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
                    break;
            }
        }
コード例 #7
0
ファイル: Mouse.cs プロジェクト: alexhanh/Botting-Library
        /// <summary>
        /// Clicks target point relative to window set.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="mouse_button">Mouse button (MouseButtons.Left or MouseButtons.Right)</param>
        public static void Click(Point point, MouseButton mouse_button)
        {
            SetPosition(point);

            INPUT[] InputData = new INPUT[3];

            Point screen_point = ToScreen(point);
            InputData[0].mi.dx = screen_point.X;
            InputData[0].mi.dy = screen_point.Y;

            InputData[0].mi.dwFlags = (int)(Flags.MOUSEEVENTF_ABSOLUTE | Flags.MOUSEEVENTF_MOVE);

            if ((mouse_button & MouseButton.Left) == MouseButton.Left)
            {
                InputData[1].mi.dwFlags = (int)Flags.MOUSEEVENTF_LEFTDOWN;
                InputData[2].mi.dwFlags = (int)Flags.MOUSEEVENTF_LEFTUP;
            }
            else if ((mouse_button & MouseButton.Right) == MouseButton.Right)
            {
                InputData[1].mi.dwFlags = (int)Flags.MOUSEEVENTF_RIGHTDOWN;
                InputData[2].mi.dwFlags = (int)Flags.MOUSEEVENTF_RIGHTUP;
            }
            else
            {
                Console.WriteLine("unknown mouse button");
                return;
            }

            if (SendInput(3, InputData, Marshal.SizeOf(InputData[0])) == 0)
            {
                Console.WriteLine("SendInput mouse error");
            }
        }
コード例 #8
0
ファイル: KeyboardSender.cs プロジェクト: pandabear41/MWAPI
        /// <summary>
        /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS.
        /// </summary>
        /// <param name="keyCode">The HardwareKeyCode to press</param>
        public static void HardwareKeyPress(ScanCode keyCode)
        {
            var down = new INPUT();
            down.Type = (UInt32)InputType.KEYBOARD;
            down.Data.Keyboard = new KEYBDINPUT();
            down.Data.Keyboard.Vk = 0;
            down.Data.Keyboard.Scan = (UInt16)keyCode;
            down.Data.Keyboard.Flags = KeyboardFlag.SCANCODE;
            down.Data.Keyboard.Time = 0;
            down.Data.Keyboard.ExtraInfo = IntPtr.Zero;

            var up = new INPUT();
            up.Type = (UInt32)InputType.KEYBOARD;
            up.Data.Keyboard = new KEYBDINPUT();
            up.Data.Keyboard.Vk = 0;
            up.Data.Keyboard.Scan = (UInt16)keyCode;
            up.Data.Keyboard.Flags = KeyboardFlag.SCANCODE | KeyboardFlag.KEYUP;
            up.Data.Keyboard.Time = 0;
            up.Data.Keyboard.ExtraInfo = IntPtr.Zero;

            if (((int)keyCode & 0xFF00) == 0xE000)
            { // extended key?
                down.Data.Keyboard.Flags |= KeyboardFlag.EXTENDEDKEY;
                up.Data.Keyboard.Flags |= KeyboardFlag.EXTENDEDKEY;
            }

            INPUT[] inputList = new INPUT[2];
            inputList[0] = down;
            inputList[1] = up;

            var numberOfSuccessfulSimulatedInputs = SendInput(2, inputList, Marshal.SizeOf(typeof(INPUT)));
            if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key press simulation for {0} was not successful.", keyCode));
        }
コード例 #9
0
ファイル: MediaControl.cs プロジェクト: barometz/flintlock
 static void SendKey(short keycode)
 {
     KEYBDINPUT ki = new KEYBDINPUT()
     {
         time = 0,
         wScan = 0,
         dwExtraInfo = (IntPtr)0,
         wVk = keycode,
         dwFlags = 0
     };
     if (IntPtr.Size > 4)
     {
         // 64-bit environment
         INPUT64 ip = new INPUT64();
         ip.type = 1; // Indicates a keyboard event
         ip.ki = ki;
         SendInput(1, new INPUT64[] { ip }, Marshal.SizeOf(ip));
         ip.ki.dwFlags = 2;
         SendInput(1, new INPUT64[] { ip }, Marshal.SizeOf(ip));
     }
     else
     {
         // 32-bit environment
         INPUT ip = new INPUT();
         ip.type = 1; // Indicates a keyboard event
         ip.ki = ki;
         // Press..
         SendInput(1, new INPUT[] { ip }, Marshal.SizeOf(ip));
         ip.ki.dwFlags = 2;
         // And let go.
         SendInput(1, new INPUT[] { ip }, Marshal.SizeOf(ip));
     }
 }
コード例 #10
0
        public static void Jiggle(int dx, int dy)
        {
            INPUT[] inputs = new INPUT[]
            {
                new INPUT
                {
                    type = INPUT_MOUSE,
                    u = new InputUnion
                    {
                        mi = new MOUSEINPUT
                        {
                            dx=dx,
                            dy= dy,
                            mouseData = 0,
                                dwFlags = MOUSEEVENTF_MOVE,
                                dwExtraInfo=(IntPtr) 0,
                                time=0
                        }
                    }
                }
            };

            if (SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT))) != 1)
            {
                throw new Win32Exception();
            }
        }
コード例 #11
0
ファイル: KeySender.cs プロジェクト: Tilps/Stash
        public static void SendString(string toSend)
        {
            INPUT input = new INPUT();
            input.type = 1;
            input.mkhi.ki.dwFlags |= KEYEVENTF_SCANCODE;

            foreach (char c in toSend)
            {
                ushort code;
                bool shift;
                MapToCode(c, out code, out shift);
                if (code == 0)
                    continue;
                if (shift)
                {
                    input.mkhi.ki.wScan = 0x2A;
                    SendInput(1, ref input, Marshal.SizeOf(typeof(INPUT)));
                }
                input.mkhi.ki.wScan = code;
                SendInput(1, ref input, Marshal.SizeOf(typeof(INPUT)));
                input.mkhi.ki.dwFlags |= KEYEVENTF_KEYUP;
                SendInput(1, ref input, Marshal.SizeOf(typeof(INPUT)));
                if (shift)
                {
                    input.mkhi.ki.wScan = 0x2A;
                    SendInput(1, ref input, Marshal.SizeOf(typeof(INPUT)));
                }
                input.mkhi.ki.dwFlags &= ~KEYEVENTF_KEYUP;
            }
        }
コード例 #12
0
 public unsafe void DispatchInput(INPUT* inputs, uint count)
 {
     var successful = NativeMethods.SendInput(count, inputs, Marshal.SizeOf(typeof(INPUT)));
     if (successful != count)
         throw new Exception("Some simulated input commands were not sent successfully. The most common reason for this happening are the security features of Windows including User Interface Privacy Isolation (UIPI). Your application can only send commands to applications of the same or lower elevation. Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the project home page and the code samples for more information.");
 
 }
コード例 #13
0
ファイル: MouseSimulator.cs プロジェクト: user-mfp/IMI
        // And a wrapper for it
        static bool sendInput(INPUT input)
        {
            INPUT[] inputList = new INPUT[1];
            inputList[0] = input;

            var numberOfSuccessfulSimulatedInputs = NativeMethods.SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT)));
            return numberOfSuccessfulSimulatedInputs > 0;
        }
コード例 #14
0
 /// <summary>
 /// Press the key corresponding to the specified scancode up.
 /// </summary>
 /// <param name="scanCode">The scancode of the key to press up.</param>
 public static void KeyUp(ushort scanCode)
 {
     INPUT[] inputs = new INPUT[1];
     inputs[0].type = WindowsAPI.INPUT_KEYBOARD;
     inputs[0].ki.wScan = scanCode;
     inputs[0].ki.dwFlags = WindowsAPI.KEYEVENTF_KEYUP | WindowsAPI.KEYEVENTF_SCANCODE;
     WindowsAPI.SendInput(1, inputs, System.Runtime.InteropServices.Marshal.SizeOf(inputs[0]));
 }
コード例 #15
0
 //press key
 public static void Stroke(ushort ScanCode)
 {
     INPUT[] InputData = new INPUT[1];
     InputData[0].type = 1;
     InputData[0].wScan = (ushort)ScanCode;
     InputData[0].dwFlags = (uint)SendInputFlags.KEYEVENTF_SCANCODE;
     SendInput(1, InputData, Marshal.SizeOf(InputData[0]));
 }
コード例 #16
0
 /// <summary>
 /// Dispatches the specified list of <see cref="INPUT"/> messages in their specified order by issuing a single called to <see cref="WindowsInput.Native.NativeMethods.SendInput"/>.
 /// </summary>
 /// <param name="inputs">The list of <see cref="INPUT"/> messages to be dispatched.</param>
 /// <exception cref="ArgumentException">If the <paramref name="inputs"/> array is empty.</exception>
 /// <exception cref="ArgumentNullException">If the <paramref name="inputs"/> array is null.</exception>
 /// <exception cref="Exception">If the any of the commands in the <paramref name="inputs"/> array could not be sent successfully.</exception>
 public void DispatchInput(INPUT[] inputs)
 {
     if (inputs == null) throw new ArgumentNullException("inputs");
     if (inputs.Length == 0) throw new ArgumentException("The input array was empty", "inputs");
     var successful = NativeMethods.SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof (INPUT)));
     if (successful != inputs.Length)
         throw new Exception("Some simulated input commands were not sent successfully. The most common reason for this happening are the security features of Windows including User Interface Privacy Isolation (UIPI). Your application can only send commands to applications of the same or lower elevation. Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the project home page and the code samples for more information.");
 }
コード例 #17
0
ファイル: MouseSimulator.cs プロジェクト: faddison/KMouse
 public static void mouseWheel(uint WHEEL_DELTA)
 {
     INPUT mouseWheelInput = new INPUT();
     mouseWheelInput.type = SendInputEventType.InputMouse;
     mouseWheelInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_WHEEL;
     mouseWheelInput.mkhi.mi.mouseData = WHEEL_DELTA;
     SendInput(1, ref mouseWheelInput, Marshal.SizeOf(new INPUT()));
 }
コード例 #18
0
ファイル: MouseController.cs プロジェクト: mecab/MouseMover
        public static void RightClick()
        {
            var inputs = new INPUT[2];
            inputs[0].mi.dwFlags = MouseEvent.RIGHTDOWN;
            inputs[1].mi.dwFlags = MouseEvent.RIGHTUP;

            SendInput(2, inputs, Marshal.SizeOf(inputs[0]));
        }
コード例 #19
0
ファイル: MouseController.cs プロジェクト: mecab/MouseMover
        public static void Wheel(int amount)
        {
            var inputs = new INPUT[1];
            inputs[0].mi.dwFlags = MouseEvent.WHEEL | MouseEvent.ABSOLUTE;
            inputs[0].mi.mouseData = - amount * WHEEL_DELTA;

            SendInput(1, inputs, Marshal.SizeOf(inputs[0]));
        }
コード例 #20
0
 public static void MoveMouse(int offsetX, int offsetY)
 {
     var mouseDownInput = new INPUT();
     mouseDownInput.type = SendInputEventType.InputMouse;
     mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_MOVE;
     mouseDownInput.mkhi.mi.dx = offsetX;
     mouseDownInput.mkhi.mi.dy = offsetY;
     SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));
 }
コード例 #21
0
        public int MouseClick(int clickID, int persistance ,IntPtr handle)
        {
            int clickResult = (int)ResultCodes.Success;
            do
            {

                var mouseMove = new INPUT();

                mouseMove.Type = (UInt32)KeyBoardScanCodes.InputType.Mouse;
                mouseMove.Data.Mouse = new MOUSEINPUT();

                //mouseMove.Data.Mouse.Flags = (UInt32)MouseScanCodes.MOUSEEVENTF_ABSOLUTE | (UInt32)MouseScanCodes.MOUSEEVENTF_MOVE;
                if (clickID == (int)MouseButton.LEFT_MOUSE_BUTTON && persistance == (int)MousePresistance.PRESS_AND_HOLD)
                {
                    mouseMove.Data.Mouse.Flags = (UInt32)MouseScanCodes.MOUSEEVENTF_LEFTDOWN;
                }
                else if (clickID == (int)MouseButton.LEFT_MOUSE_BUTTON && persistance == (int)MousePresistance.RELEASE)
                {
                    mouseMove.Data.Mouse.Flags = (UInt32)MouseScanCodes.MOUSEEVENTF_LEFTUP;
                }
                else if (clickID == (int)MouseButton.RIGHT_MOUSE_BUTTON && persistance == (int)MousePresistance.PRESS_AND_HOLD)
                {
                    mouseMove.Data.Mouse.Flags = (UInt32)MouseScanCodes.MOUSEEVENTF_RIGHTDOWN;
                }
                else if (clickID == (int)MouseButton.RIGHT_MOUSE_BUTTON && persistance == (int)MousePresistance.RELEASE)
                {
                    mouseMove.Data.Mouse.Flags = (UInt32)MouseScanCodes.MOUSEEVENTF_RIGHTUP;
                }
                else { }

                mouseMove.Data.Mouse.Time = 0;
                mouseMove.Data.Mouse.MouseData = 0;

                INPUT[] inputMouse = new INPUT[1];
                inputMouse[0] = mouseMove;

                //Set the active window to be the game (through its handle) to receive the input
                SetActiveWindow(handle);

                //set the focus of the input to be given to the game
                SetFocus(handle);

                //Sleep to ensure all the actions are performed
                System.Threading.Thread.Sleep(safetySleepTime);

                clickResult = (int)SendInput(1, inputMouse, Marshal.SizeOf(typeof(INPUT)));

                if (clickResult <= 0)
                {
                    clickResult = (int)ResultCodes.MouseInputFailed;
                    break;
                }

            } while (false);

            return clickResult;
        }
コード例 #22
0
    public static void DoubleClick(int pos_x, int pos_y)
    {
        // マウス操作実行用のデータ
        const int num = 5;
        INPUT[] inp = new INPUT[num];

        // マウスカーソルを移動する
        inp[0].type = INPUT_MOUSE;
        inp[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
        inp[0].mi.dx = pos_x * (65535 / Screen.width);
        inp[0].mi.dy = pos_y * (65535 / Screen.height);
        inp[0].mi.mouseData = 0;
        inp[0].mi.dwExtraInfo = 0;
        inp[0].mi.time = 0;

        // マウスの左ボタンを押す
        inp[1].type = INPUT_MOUSE;
        inp[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
        inp[1].mi.dx = 0;
        inp[1].mi.dy = 0;
        inp[1].mi.mouseData = 0;
        inp[1].mi.dwExtraInfo = 0;
        inp[1].mi.time = 0;

        // マウスの左ボタンを離す
        inp[2].type = INPUT_MOUSE;
        inp[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
        inp[2].mi.dx = 0;
        inp[2].mi.dy = 0;
        inp[2].mi.mouseData = 0;
        inp[2].mi.dwExtraInfo = 0;
        inp[2].mi.time = 0;

        // マウスの左ボタンを押す
        inp[3].type = INPUT_MOUSE;
        inp[3].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
        inp[3].mi.dx = 0;
        inp[3].mi.dy = 0;
        inp[3].mi.mouseData = 0;
        inp[3].mi.dwExtraInfo = 0;
        inp[3].mi.time = 0;

        // マウスの左ボタンを離す
        inp[4].type = INPUT_MOUSE;
        inp[4].mi.dwFlags = MOUSEEVENTF_LEFTUP;
        inp[4].mi.dx = 0;
        inp[4].mi.dy = 0;
        inp[4].mi.mouseData = 0;
        inp[4].mi.dwExtraInfo = 0;
        inp[4].mi.time = 0;

        // マウス操作実行
        SendInput(num, ref inp[0], Marshal.SizeOf(inp[0]));

        Debug.Log("VirtualInput :: Mouse Double Click [ " + pos_x.ToString() + " , " + pos_y.ToString() + " ]");
    }
コード例 #23
0
        /// <summary>
        /// Simulates the mouse right click.
        /// </summary>
        public static void SimulateMouseRightClick()
        {
            var mouseDownInput = new INPUT { SendInputEventType = SendInputEventType.InputMouse };
            mouseDownInput.MouseKeyboardInputUnion.MouseInput.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN;
            SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

            var mouseUpInput = new INPUT { SendInputEventType = SendInputEventType.InputMouse };
            mouseUpInput.MouseKeyboardInputUnion.MouseInput.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTUP;
            SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
        }
コード例 #24
0
 public void LeftMouseClick(int x, int y)
 {
     MoveCursorToPoint(x, y);
     INPUT[] inp = new INPUT[2];
     inp[0].type = INPUT_MOUSE;
     inp[0].mi = createMouseInput(0, 0, 0, 0, MOUSEEVENTF_LEFTDOWN);
     inp[1].type = INPUT_MOUSE;
     inp[1].mi = createMouseInput(0, 0, 0, 0, MOUSEEVENTF_LEFTUP);
     SendInput((uint)inp.Length, inp, Marshal.SizeOf(inp[0].GetType()));
 }
コード例 #25
0
 public static void SendInput(INPUT[] inputs)
 {
     for (int i = 0; i < inputs.Length; i++)
         if (inputs[i].type == InputType.INPUT_KEYBOARD)
         {
             inputs[i].ki.wScan = (ushort)MapVirtualKey(inputs[i].ki.wVk, 0);
             inputs[i].ki.time = 0;
             inputs[i].ki.dwExtraInfo = GetMessageExtraInfo();
         }
     SendInput(inputs.Length, inputs, System.Runtime.InteropServices.Marshal.SizeOf(inputs[0]));
 }
コード例 #26
0
 private INPUT BuildKeyInput(KeyboardData keyData)
 {
     INPUT input = new INPUT();
     input.mType = SENDINPUTEVENTTYPE.INPUT_KEYBOARD;
     input.mInputUnion.ki = new KEYBDINPUT
     {
         wVk = (short)keyData.Key.Code,
         dwFlags = (KeyState)keyData.State == KeyState.KeyUp ? KEYEVENTF.KEYUP : KEYEVENTF.NONE,
     };
     return input;
 }
コード例 #27
0
ファイル: MouseSimulator.cs プロジェクト: alexxsun/RealSense
        public static void ClickRightMouseButton() {
            INPUT mouseDownInput = new INPUT();
            mouseDownInput.type = SendInputEventType.InputMouse;
            mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN;
            SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

            INPUT mouseUpInput = new INPUT();
            mouseUpInput.type = SendInputEventType.InputMouse;
            mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTUP;
            SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
        }
コード例 #28
0
ファイル: VirtualKeyboard.cs プロジェクト: NotYours180/Vocals
        public static void SendKey(uint keyCode, KeyFlag keyFlag) {
            INPUT InputData = new INPUT();

            InputData.type = 1;
            InputData.ki.scanCode = (ushort)keyCode;
            InputData.ki.flags = (uint)keyFlag;
            Console.WriteLine(InputData.ki.scanCode);
            Console.WriteLine(keyCode);

            SendInput((uint)1, ref InputData, (int)Marshal.SizeOf(typeof(INPUT)));
        }
コード例 #29
0
		const int screen_length = 0x10000;  // for MOUSEEVENTF_ABSOLUTE (この値は固定)

		public static void Move(int x, int y)
		{
			int h = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
			int w = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;

			INPUT[] input = new INPUT[1];
			input[0].mi.dx = (x * screen_length) / w;
			input[0].mi.dy = (y * screen_length) / h;
			input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;

			SendInput(1, input, Marshal.SizeOf(input[0]));
		}
コード例 #30
0
ファイル: test.cs プロジェクト: felenko/TcmAutomationHelper
 public static uint Click()
 {
     INPUT structure = new INPUT();
     structure.mi.dx = 0;
     structure.mi.dy = 0;
     structure.mi.mouseData = 0;
     structure.mi.dwFlags = 2;
     INPUT input2 = structure;
     input2.mi.dwFlags = 4;
     INPUT[] pInputs = new INPUT[] { structure, input2 };
     return SendInput(2, pInputs, Marshal.SizeOf(structure));
 }
コード例 #31
0
ファイル: Handler.cs プロジェクト: kovachwt/SymWin
        private static void _SendSelectedLetterAsKeyPress(Boolean delayInput = false)
        {
            var pos    = Caret.GetPosition(_sActiveKeyboardWindow);
            var letter = _sActiveSelectorWindow.SelectedLetter;

            _HidePopup();

            try
            {
                if (!SetForegroundWindow(_sActiveKeyboardWindow))
                {
                    // Something went wrong, ignore.
                    return;
                }
            }
            catch (Win32Exception e)
            {
                // For reasons not yet understood we sometimes get a 0 error code turned into an exception (operation succeeded).
                if (e.NativeErrorCode != 0)
                {
                    return;
                }
            }

            var keyboardInput = new KEYBDINPUT();

            keyboardInput.wVk         = 0; // required by unicode event
            keyboardInput.wScan       = (Int16)letter;
            keyboardInput.dwFlags     = KEYEVENTF.UNICODE;
            keyboardInput.dwExtraInfo = GetMessageExtraInfo();
            keyboardInput.time        = 0;

            var keyDown = new INPUT();

            keyDown.type = INPUT_KEYBOARD;
            keyDown.U.ki = keyboardInput;

            var keyUp = keyDown;

            keyUp.U.ki.dwFlags |= KEYEVENTF.KEYUP;

            // If an error happens here it's probably due to UIPI, i.e. the target application is of higher integrity.
            // We ignore the error.
            if (delayInput)
            {
                ThreadPool.QueueUserWorkItem(context =>
                {
                    // Just block for a bit.
                    Thread.Sleep(_kReleaseErrorMargin);

                    ((SynchronizationContext)context).Post(_ =>
                    {
                        SendInput(2, new[] { keyDown, keyUp }, Marshal.SizeOf(keyDown));
                    }, null);
                }, SynchronizationContext.Current);
            }
            else
            {
                SendInput(2, new[] { keyDown, keyUp }, Marshal.SizeOf(keyDown));
            }
        }
コード例 #32
0
        public void KeyUp(KeyMap CurrentKey, string ExtraData = "")
        {
            //A special key has been released
            //Determine the type of Special Key being pressed
            //Added for Issue #19
            switch (CurrentKey.Type)
            {
            case 4:
            {
                //4 = Special Key (Mouse, Media, etc)
                switch (CurrentKey.Action)
                {
                case 0:
                {
                    //Left Mouse Button
                    //mouse_event(0x04, 0, 0, 0, 0);
                    INPUT input_up = new INPUT();
                    input_up.type         = INPUT_MOUSE;
                    input_up.mi.dx        = 0;
                    input_up.mi.dy        = 0;
                    input_up.mi.mouseData = 0;
                    input_up.mi.dwFlags   = (int)MOUSEEVENTF_LEFTUP;

                    INPUT[] input = { input_up };

                    SendInput(1, input, Marshal.SizeOf(input_up));
                    break;
                }

                case 1:
                {
                    //Right Mouse Button
                    INPUT input_up = new INPUT();
                    input_up.type         = INPUT_MOUSE;
                    input_up.mi.dx        = 0;
                    input_up.mi.dy        = 0;
                    input_up.mi.mouseData = 0;
                    input_up.mi.dwFlags   = (int)MOUSEEVENTF_RIGHTUP;

                    INPUT[] input = { input_up };

                    SendInput(1, input, Marshal.SizeOf(input_up));
                    break;
                }

                case 2:
                {
                    //Middle Mouse Button
                    INPUT input_up = new INPUT();
                    input_up.type         = INPUT_MOUSE;
                    input_up.mi.dx        = 0;
                    input_up.mi.dy        = 0;
                    input_up.mi.mouseData = 0;
                    input_up.mi.dwFlags   = (int)MOUSEEVENTF_MIDDLEUP;

                    INPUT[] input = { input_up };

                    SendInput(1, input, Marshal.SizeOf(input_up));
                    break;
                }

                default:
                {
                    //Used for any Special Key that can be sent just with the SpecialValue to the Keyboard Input
                    INPUT input_up = new INPUT();
                    input_up.type           = INPUT_KEYBOARD;
                    input_up.ki.wVk         = _SpecialKeys[CurrentKey.Action].SpecialValue;
                    input_up.ki.wScan       = 0;
                    input_up.ki.dwExtraInfo = IntPtr.Zero;
                    input_up.ki.dwFlags     = KEYEVENTF_KEYUP;

                    INPUT[] input = { input_up };

                    SendInput(1, input, Marshal.SizeOf(input_up));
                    break;
                }
                }
                break;
            }

            case 5:
            {
                //5 = Toggle Key
                //Added for Issue #19

                switch (Bags.getValue(CurrentKey.Action))
                {
                case 1:
                {
                    //One Key-up has already been ignored, take this one and release the Key
                    INPUT input_down = new INPUT();
                    input_down.type           = INPUT_KEYBOARD;
                    input_down.ki.wVk         = CurrentKey.Action;
                    input_down.ki.wScan       = 0;
                    input_down.ki.dwExtraInfo = IntPtr.Zero;
                    input_down.ki.dwFlags     = KEYEVENTF_KEYUP;

                    INPUT[] input = { input_down };

                    SendInput(1, input, Marshal.SizeOf(input_down));
                    //Remove Key being "pressed" from Dictionary so it isn't released again later
                    Bags.RemoveToggle(CurrentKey.Action);
                    DebugLog.Instance.writeLog("         Key Upped: " + CurrentKey.Action);
                    break;
                }

                case 2:
                {
                    //Key just pressed ignore this key-up, change State to 1
                    Bags.DecValue(CurrentKey.Action);
                    DebugLog.Instance.writeLog("         First Key Up ignored: " + CurrentKey.Action);
                    break;
                }

                default:
                {
                    //Should never hit here.
                    DebugLog.Instance.writeLog("         Unknown State for key: " + CurrentKey.Action);
                    break;
                }
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }
コード例 #33
0
ファイル: Keyboard.cs プロジェクト: sidiandi/TeamsPushToTalk
        public static bool ForegroundKeyPressAll(IntPtr hWnd, Key key, bool alt, bool ctrl, bool shift, int delay = 100)
        {
            if (GetForegroundWindow() != hWnd)
            {
                if (!SetForegroundWindow(hWnd))
                {
                    return(false);
                }
            }
            uint  intReturn;
            INPUT structInput;

            structInput      = new INPUT();
            structInput.type = INPUT_KEYBOARD;

            // Key down shift, ctrl, and/or alt
            structInput.u.ki.wScan   = 0;
            structInput.u.ki.time    = 0;
            structInput.u.ki.dwFlags = 0;
            if (alt)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_MENU;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            if (ctrl)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_CONTROL;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            if (shift)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_SHIFT;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);

                if (key.ShiftKey != VKeys.NULL)
                {
                    structInput.u.ki.wVk = (ushort)key.ShiftKey;
                    intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                    Thread.Sleep(delay);
                }
            }

            // Key up the actual key-code
            ForegroundKeyPress(hWnd, key);

            structInput.u.ki.dwFlags = KEYEVENTF_KEYUP;
            if (shift && key.ShiftKey == VKeys.NULL)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_SHIFT;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            if (ctrl)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_CONTROL;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            if (alt)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_MENU;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            return(true);
        }
コード例 #34
0
ファイル: Keyboard.cs プロジェクト: sidiandi/TeamsPushToTalk
        public static bool SendMessageAll(IntPtr hWnd, Key key, bool alt, bool ctrl, bool shift, int delay = 100)
        {
            CheckKeyShiftState();
            uint  intReturn;
            INPUT structInput = new INPUT
            {
                type = INPUT_KEYBOARD,
                u    = new InputUnion
                {
                    ki = { wScan = 0, time = 0, dwFlags = 0 }
                }
            };

            // Key down shift, ctrl, and/or alt
            if (alt)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_MENU;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            if (ctrl)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_CONTROL;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            if (shift)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_SHIFT;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);

                if (key.ShiftKey != VKeys.NULL)
                {
                    //Send KEY_DOWN
                    if (SendMessage(hWnd, (int)Message.KEY_DOWN, (uint)key.Vk, GetLParam(1, key.ShiftKey, 0, 0, 0, 0)))
                    {
                        return(false);
                    }
                    Thread.Sleep(delay);
                }
            }

            SendMessage(hWnd, key, false);

            structInput.u.ki.dwFlags = KEYEVENTF_KEYUP;
            if (shift && key.ShiftKey == VKeys.NULL)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_SHIFT;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            if (ctrl)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_CONTROL;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }
            if (alt)
            {
                structInput.u.ki.wVk = (ushort)VKeys.KEY_MENU;
                intReturn            = SendInput(1, new[] { structInput }, Marshal.SizeOf(new INPUT()));
                Thread.Sleep(delay);
            }

            return(true);
        }
コード例 #35
0
 private extern static uint SendInput(int nInputs, ref INPUT pInputs, int cbsize);
コード例 #36
0
        public void Send(int key, bool isEXTEND)
        {
            Console.WriteLine("Gd");

            //원래코드
            INPUT inp = new INPUT();

            inp.type           = INPUT_KEYBOARD;
            inp.ki.wVk         = (short)key;
            inp.ki.wScan       = (short)MapVirtualKey(inp.ki.wVk, 0);
            inp.ki.dwFlags     = ((isEXTEND) ? (KEYEVENTF_EXTENDEDKEY) : 0x0) | KEYEVENTF_KEYDOWN;
            inp.ki.time        = 0;
            inp.ki.dwExtraInfo = 0;
            SendInput(1, ref inp, Marshal.SizeOf(inp));
            System.Threading.Thread.Sleep(100);
            inp.ki.dwFlags = ((isEXTEND) ? (KEYEVENTF_EXTENDEDKEY) : 0x0) | KEYEVENTF_KEYUP;
            SendInput(1, ref inp, Marshal.SizeOf(inp));
            //원래코드

            //i[0] = new INPUT();
            //i[0].type = INPUT_KEYBOARD;
            //i[0].ki.wVk = (short)key;
            //i[0].ki.wScan = (short)MapVirtualKey(i[0].ki.wVk, 0);
            //i[0].ki.dwFlags = ((isEXTEND) ? (KEYEVENTF_EXTENDEDKEY) : 0x0) | KEYEVENTF_KEYDOWN;
            //i[0].ki.time = 0;
            //i[0].ki.dwExtraInfo = 0;

            ////i[1] = new INPUT();

            ////i[1].type = INPUT_KEYBOARD;
            ////i[1].ki.wVk = (short)key;
            ////i[1].ki.wScan = (short)MapVirtualKey(i[1].ki.wVk, 0);
            ////i[1].ki.dwFlags = ((isEXTEND) ? (KEYEVENTF_EXTENDEDKEY) : 0x0) | KEYEVENTF_KEYDOWN;
            ////i[1].ki.time = 0;
            ////i[1].ki.dwExtraInfo = 0;

            //INPUT input = new INPUT();

            //input.type = INPUT_KEYBOARD;
            //input.ki.wVk = (short)key;
            //input.ki.wScan = (short)MapVirtualKey(input.ki.wVk, 0);
            //input.ki.dwFlags = ((isEXTEND) ? (KEYEVENTF_EXTENDEDKEY) : 0x0) | KEYEVENTF_KEYDOWN;
            //input.ki.time = 0;
            //input.ki.dwExtraInfo = 0;

            //inputs.Add(input);


            //input = new INPUT();

            //input.type = INPUT_KEYBOARD;
            //input.ki.wVk = (short)65;
            //input.ki.wScan = (short)MapVirtualKey(input.ki.wVk, 0);
            //input.ki.dwFlags = ((isEXTEND) ? (KEYEVENTF_EXTENDEDKEY) : 0x0) | KEYEVENTF_KEYDOWN;
            //input.ki.time = 0;
            //input.ki.dwExtraInfo = 0;
            //inputs.Add(input);

            //input = new INPUT();

            //input.type = INPUT_KEYBOARD;
            //input.ki.wVk = (short)66;
            //input.ki.wScan = (short)MapVirtualKey(input.ki.wVk, 0);
            //input.ki.dwFlags = ((isEXTEND) ? (KEYEVENTF_EXTENDEDKEY) : 0x0) | KEYEVENTF_KEYDOWN;
            //input.ki.time = 0;
            //input.ki.dwExtraInfo = 0;
            //inputs.Add(input);
            //uint result = SendInput(inputs.Count, inputs.ToArray(), Marshal.SizeOf(inputs[0]));
            //if (result == 0)
            //    throw new Win32Exception(Marshal.GetLastWin32Error());

            //inputs.Clear();
            //Console.WriteLine("결과값");
            //System.Threading.Thread.Sleep(100);
            //inp.ki.dwFlags = ((isEXTEND) ? (KEYEVENTF_EXTENDEDKEY) : 0x0) | KEYEVENTF_KEYUP;
            //SendInput(1, ref inp, Marshal.SizeOf(inp));
        }
コード例 #37
0
        public void WiiControl(WiimoteState ws)
        {
            INPUT[] input = new INPUT[1];
            if (ws.ButtonState.B)
            {
                GyroMouse(ws);
            }
            if (ws.ButtonState.A)
            {
                if (!isADown)
                {
                    input[0].mi.dwFlags = 0x0002;
                    SendInput(1, input, Marshal.SizeOf(input[0]));
                    isADown = true;
                }
            }
            else
            {
                if (isADown)
                {
                    isADown = false;

                    input[0].mi.dwFlags = 0x0004;
                    SendInput(1, input, Marshal.SizeOf(input[0]));
                }
            }


            if (ws.ButtonState.One)
            {
                if (!isOneDown)
                {
                    input[0].mi.dwFlags = 0x0008;
                    SendInput(1, input, Marshal.SizeOf(input[0]));

                    isOneDown = true;
                }
            }
            else
            {
                if (isOneDown)
                {
                    isOneDown           = false;
                    input[0].mi.dwFlags = 0x0010;
                    SendInput(1, input, Marshal.SizeOf(input[0]));
                }
            }
            if (ws.ButtonState.Up)
            {
                if (!isUpDown)
                {
                    win32api.keybd_event(VK_UP, 0, 0, (UIntPtr)0);
                    isUpDown = true;
                }
            }
            else
            {
                if (isUpDown)
                {
                    win32api.keybd_event(VK_UP, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);

                    isUpDown = false;
                }
            }

            if (ws.ButtonState.Down)
            {
                if (!isDownDown)
                {
                    win32api.keybd_event(VK_DOWN, 0, 0, (UIntPtr)0);
                    isDownDown = true;
                }
            }
            else
            {
                if (isDownDown)
                {
                    win32api.keybd_event(VK_DOWN, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);

                    isDownDown = false;
                }
            }


            if (ws.ButtonState.Right)
            {
                if (!isRightDown)
                {
                    win32api.keybd_event(VK_RIGHT, 0, 0, (UIntPtr)0);
                    isRightDown = true;
                }
            }
            else
            {
                if (isRightDown)
                {
                    win32api.keybd_event(VK_RIGHT, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);

                    isRightDown = false;
                }
            }


            if (ws.ButtonState.Left)
            {
                if (!isLeftDown)
                {
                    win32api.keybd_event(VK_LEFT, 0, 0, (UIntPtr)0);
                    isLeftDown = true;
                }
            }
            else
            {
                if (isLeftDown)
                {
                    win32api.keybd_event(VK_LEFT, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);

                    isLeftDown = false;
                }
            }


            if (ws.ButtonState.Plus)
            {
                if (!isPlusDown)
                {
                    isPlusDown = true;


                    win32api.keybd_event(VK_ENTER, 0, 0, (UIntPtr)0);
                }
            }
            else
            {
                if (isPlusDown)
                {
                    win32api.keybd_event(VK_ENTER, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);

                    isPlusDown = false;
                }
            }


            if (ws.ButtonState.Minus)
            {
                if (!isMinusDown)
                {
                    win32api.keybd_event(VK_BS, 0, 0, (UIntPtr)0);
                    isMinusDown = true;
                }
            }
            else
            {
                if (isMinusDown)
                {
                    win32api.keybd_event(VK_BS, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);

                    isMinusDown = false;
                }
            }

            if (ws.ButtonState.Home)
            {
                if (!isHomeDown)
                {
                    win32api.keybd_event(VK_WINDOWS, 0, 0, (UIntPtr)0);
                    isHomeDown = true;
                }
            }
            else
            {
                if (isHomeDown)
                {
                    win32api.keybd_event(VK_WINDOWS, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);

                    isHomeDown = false;
                }
            }


            if (ws.ButtonState.Two)
            {
                if (!isTwoDown)
                {
                    win32api.keybd_event(VK_TAB, 0, 0, (UIntPtr)0);
                    isTwoDown = true;
                }
            }
            else
            {
                if (isTwoDown)
                {
                    win32api.keybd_event(VK_TAB, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);
                    win32api.keybd_event(VK_DOWN, 0, 0, (UIntPtr)0);
                    win32api.keybd_event(VK_DOWN, 0, 2 /*KEYEVENTF_KEYUP*/, (UIntPtr)0);

                    isTwoDown = false;
                }
            }


            if (ws.ButtonState.B)
            {
                if (!isBDown)
                {
                    isBDown = true;
                }
            }
            else
            {
                if (isBDown)
                {
                    isBDown = false;
                }
            }
        }
コード例 #38
0
 private static extern uint SendInput(
     uint nInputs,     // count of input events
     ref INPUT input,
     int cbSize        // size of structure
     );
コード例 #39
0
 public static extern int SendInput(int nInputs, ref INPUT mi, int cbSize);
コード例 #40
0
 internal static extern Int32 SendInput(Int32 cInputs, ref INPUT pInputs, Int32 cbSize);
コード例 #41
0
        public static async Task ClickAndDragAsync(IntPtr wndHandle, Config config)
        {
            var clientPoint  = new Point(config.XPos, config.YPos);
            var clientPoint2 = new Point(config.XPosMoved, config.YPosMoved);

            var allPoints = Line.GetPoints(clientPoint, clientPoint2, 10);

            var oldPos = Cursor.Position;

            //ClientToScreen(wndHandle, ref clientPoint2);

            if (config.IsPositionIgnoredValid)
            {
                //var ignoredPoint = new Point(config.XPosIgnored, config.YPosIgnored);
                //ClientToScreen(wndHandle, ref ignoredPoint);
                var newIgnoredColor = GetColorAt(new Point(config.XPosIgnored, config.YPosIgnored));
                if (newIgnoredColor.Name == config.ColorIgnoredName)
                {
                    return;
                }
            }

            //var colorClientPoint = clientPoint;
            //ClientToScreen(wndHandle, ref colorClientPoint);
            var color = GetColorAt(clientPoint);

            if (color.Name == config.ColorName)
            {
                var inputMouseDown = new INPUT();
                inputMouseDown.Type             = 0;
                inputMouseDown.Data.Mouse.X     = CalculateAbsoluteCoordinateX(clientPoint.X);
                inputMouseDown.Data.Mouse.Y     = CalculateAbsoluteCoordinateY(clientPoint.Y);
                inputMouseDown.Data.Mouse.Flags = 0x0002;

                var inputMouseMove = new INPUT();
                inputMouseMove.Type             = 0;
                inputMouseMove.Data.Mouse.X     = CalculateAbsoluteCoordinateX(clientPoint.X);
                inputMouseMove.Data.Mouse.Y     = CalculateAbsoluteCoordinateY(clientPoint.Y);
                inputMouseMove.Data.Mouse.Flags = 0x8000 | 0x0001; //0x8000 | 0x0001;//0x0001;

                var inputs = new INPUT[] { inputMouseMove, inputMouseDown };
                SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
                await Task.Delay(10);

                Debug.WriteLine($"Left down");

                for (int i = 0; i < allPoints.Length; i++)
                {
                    var point = allPoints[i];

                    var inputMouseMove1 = new INPUT();
                    inputMouseMove1.Type             = 0;
                    inputMouseMove1.Data.Mouse.X     = CalculateAbsoluteCoordinateX(point.X);
                    inputMouseMove1.Data.Mouse.Y     = CalculateAbsoluteCoordinateY(point.Y);
                    inputMouseMove1.Data.Mouse.Flags = 0x8000 | 0x0001; //0x8000 | 0x0001;//0x0001;

                    var inputs1 = new INPUT[] { inputMouseMove1 };
                    SendInput((uint)inputs1.Length, inputs1, Marshal.SizeOf(typeof(INPUT)));
                    if (config.DragSlow)
                    {
                        await Task.Delay(50);
                    }
                    else
                    {
                        await Task.Delay(10);
                    }

                    Debug.WriteLine($"Move");
                }
                var inputMouseUp = new INPUT();
                inputMouseUp.Type             = 0;
                inputMouseUp.Data.Mouse.Flags = 0x0004;

                var inputs3 = new INPUT[] { inputMouseUp };
                SendInput((uint)inputs3.Length, inputs3, Marshal.SizeOf(typeof(INPUT)));
                await Task.Delay(100);

                Debug.WriteLine($"Left Up");

                Cursor.Position = oldPos;
            }
        }
コード例 #42
0
ファイル: BaseHook.cs プロジェクト: Duque93/Hook
 internal static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
コード例 #43
0
        //[System.Runtime.InteropServices.DllImport("user32.dll")]
        //public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);


        public void KeyDown(KeyMap CurrentKey, string ExtraData = "")
        {
            //A special key has been pressed
            //Determine the type of Special Key being pressed
            //Added for Issue #19
            switch (CurrentKey.Type)
            {
            case 4:
            {
                //4 = Special Key (Mouse, Media, etc)
                switch (CurrentKey.Action)
                {
                case 0:
                {
                    //Left Mouse Button
                    //Old Code - Mostly Worked
                    //mouse_event(0x02, 0, 0, 0, 0);
                    INPUT input_down = new INPUT();
                    input_down.type         = INPUT_MOUSE;
                    input_down.mi.dx        = 0;
                    input_down.mi.dy        = 0;
                    input_down.mi.mouseData = 0;
                    input_down.mi.dwFlags   = (int)MOUSEEVENTF_LEFTDOWN;

                    INPUT[] input = { input_down };

                    SendInput(1, input, Marshal.SizeOf(input_down));
                    break;
                }

                case 1:
                {
                    //Right Mouse Button
                    INPUT input_down = new INPUT();
                    input_down.type         = INPUT_MOUSE;
                    input_down.mi.dx        = 0;
                    input_down.mi.dy        = 0;
                    input_down.mi.mouseData = 0;
                    input_down.mi.dwFlags   = (int)MOUSEEVENTF_RIGHTDOWN;

                    INPUT[] input = { input_down };

                    SendInput(1, input, Marshal.SizeOf(input_down));
                    break;
                }

                case 2:
                {
                    //Middle Mouse Button
                    INPUT input_down = new INPUT();
                    input_down.type         = INPUT_MOUSE;
                    input_down.mi.dx        = 0;
                    input_down.mi.dy        = 0;
                    input_down.mi.mouseData = 0;
                    input_down.mi.dwFlags   = (int)MOUSEEVENTF_MIDDLEDOWN;

                    INPUT[] input = { input_down };

                    SendInput(1, input, Marshal.SizeOf(input_down));
                    break;
                }

                case 3:
                {
                    //Mouse Vert Scroll
                    INPUT input_down = new INPUT();
                    input_down.type  = INPUT_MOUSE;
                    input_down.mi.dx = 0;
                    input_down.mi.dy = 0;

                    //Check to see if scrolling Up or down
                    if (CurrentKey.CustomData == "1")
                    {
                        input_down.mi.mouseData = 100;
                    }
                    else
                    {
                        input_down.mi.mouseData = -100;
                    }

                    input_down.mi.dwFlags = (int)MOUSEEVENTF_VWHEEL;

                    INPUT[] input = { input_down };

                    SendInput(1, input, Marshal.SizeOf(input_down));
                    break;
                }

                case 4:
                {
                    //Mouse Horz Scroll
                    INPUT input_down = new INPUT();
                    input_down.type  = INPUT_MOUSE;
                    input_down.mi.dx = 0;
                    input_down.mi.dy = 0;

                    //Check to see if scrolling Up or down
                    if (CurrentKey.CustomData == "1")
                    {
                        input_down.mi.mouseData = 100;
                    }
                    else
                    {
                        input_down.mi.mouseData = -100;
                    }

                    input_down.mi.dwFlags = (int)MOUSEEVENTF_HWHEEL;

                    INPUT[] input = { input_down };

                    SendInput(1, input, Marshal.SizeOf(input_down));
                    break;
                }

                //case 5:
                //    {
                //        //Media Play/Pause
                //        INPUT input_down = new INPUT();
                //        input_down.ki.wVk = (ushort)MEDIA_PLAY_PAUSE;
                //        input_down.ki.wScan = 0;
                //        input_down.ki.dwExtraInfo = IntPtr.Zero;
                //        input_down.ki.dwFlags = 0;

                //        INPUT[] input = { input_down };

                //        SendInput(1, input, Marshal.SizeOf(input_down));
                //        break;
                //    }
                default:
                {
                    //Used for any Special Key that can be sent just with the SpecialValue to the Keyboard Input
                    INPUT input_down = new INPUT();
                    input_down.type           = INPUT_KEYBOARD;
                    input_down.ki.wVk         = _SpecialKeys[CurrentKey.Action].SpecialValue;
                    input_down.ki.wScan       = 0;
                    input_down.ki.dwExtraInfo = IntPtr.Zero;
                    input_down.ki.dwFlags     = 0;

                    INPUT[] input = { input_down };

                    SendInput(1, input, Marshal.SizeOf(input_down));

                    break;
                }
                }
                break;
            }

            case 5:
            {
                //5 = Toggle Key
                //Added for Issue #19
                DebugLog.Instance.writeLog("Attempting to Toggle key: " + CurrentKey.Action, true);
                //Check if Key is "0", if so press key (Ignore key in all other states)
                if (Bags.getValue(CurrentKey.Action) == 0)
                {
                    INPUT input_down = new INPUT();
                    input_down.type           = INPUT_KEYBOARD;
                    input_down.ki.wVk         = CurrentKey.Action;
                    input_down.ki.wScan       = 0;
                    input_down.ki.dwExtraInfo = IntPtr.Zero;
                    input_down.ki.dwFlags     = 0;

                    INPUT[] input = { input_down };

                    SendInput(1, input, Marshal.SizeOf(input_down));

                    //Set Flag to "ON"
                    //Add Key being "pressed" to Dictionary for later removal
                    Bags.AddToggle(CurrentKey.Action, 2);
                    DebugLog.Instance.writeLog("         Key Toggled: " + CurrentKey.Action);
                }
                else
                {
                    DebugLog.Instance.writeLog("         Key NOT Toggled: " + CurrentKey.Action);
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }