コード例 #1
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));
     }
 }
コード例 #2
0
ファイル: Win32.cs プロジェクト: candera/tpanl
 public static uint SendInput(KeyEventSequence keys, bool sendKeysIndividually, Nullable<TimeSpan> pauseBetweenKeys)
 {
     if (IntPtr.Size == 4)
     {
         INPUT32[] inputs = keys.ToInputArray32();
         if (sendKeysIndividually)
         {
             INPUT32[] chunkedInput = new INPUT32[1];
             uint total = 0;
             for (int i = 0; i < inputs.Length; ++i)
             {
                 chunkedInput[0] = inputs[i];
                 total += Win32.SendInput32(1, chunkedInput, Marshal.SizeOf(typeof(INPUT32)));
                 if (pauseBetweenKeys.HasValue)
                 {
                     Thread.Sleep(pauseBetweenKeys.Value);
                 }
             }
             return total;
         }
         else
         {
             return Win32.SendInput32((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT32)));
         }
     }
     else if (IntPtr.Size == 8)
     {
         INPUT64[] inputs = keys.ToInputArray64();
         if (sendKeysIndividually)
         {
             INPUT64[] chunkedInput = new INPUT64[1];
             uint total = 0;
             for (int i = 0; i < inputs.Length; ++i)
             {
                 chunkedInput[0] = inputs[i];
                 total += Win32.SendInput64(1, chunkedInput, Marshal.SizeOf(typeof(INPUT64)));
                 if (pauseBetweenKeys.HasValue)
                 {
                     Thread.Sleep(pauseBetweenKeys.Value);
                 }
             }
             return total;
         }
         else
         {
             return Win32.SendInput64((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT64)));
         }
     }
     else
     {
         throw new NotSupportedException("Can't figure out platform bitness. Pointers have this width: " + IntPtr.Size.ToString());
     }
 }
コード例 #3
0
 public void MoveMouse(PointF p)
 {
     //TODO: move mouse should use a Point rather than a PointF and should get directly usable coordinates
     if (IntPtr.Size == 8)
     {
         var move = new INPUT64[1];
         move[0] = new INPUT64();
         move[0].mi.dx = (int)(p.X * 65535 / ScreenSize.Width);
         move[0].mi.dy = (int)(p.Y * 65535 / ScreenSize.Height);
         move[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
         SendInput(1, move, Marshal.SizeOf(move[0]));
     }
     else
     {
         var move = new INPUT32[1];
         move[0] = new INPUT32();
         move[0].mi.dx = (int)(p.X * 65535 / ScreenSize.Width);
         move[0].mi.dy = (int)(p.Y * 65535 / ScreenSize.Height);
         move[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
         SendInput(1, move, Marshal.SizeOf(move[0]));
     }
 }
コード例 #4
0
 static extern uint SendInput(uint nInputs, INPUT64[] pInputs, int cbSize);
コード例 #5
0
ファイル: WinAPI.cs プロジェクト: wilson0x4d/Mubox
 internal static void MouseActionViaSendInput(MouseEventFlags flags, uint time, int relX, int relY, uint mouseData)
 {
     // NOTE: this code yields strange behavior for mouse-wheel events and when panning a third-person view in most games
     // NOTE: this code also does not appear to perform mouse broadcast as expected
     // NOTE: only retaining this code for reference in the event someone can correct the misbehaviors, or in case there is ever a game that will only respect INPUT and not WM for mouse
     uint result = 0;
     if (IntPtr.Size == 8)
     {
         INPUT64[] input = new INPUT64[1];
         input[0].InputType = InputType.INPUT_MOUSE;
         input[0].mi.dwExtraInfo = GetMessageExtraInfo();
         input[0].mi.Flags = flags;
         input[0].mi.time = GetTickCount();
         input[0].mi.dx = (int)relX;
         input[0].mi.dy = (int)relY;
         input[0].mi.mouseData = mouseData;
         result = SendInput(1, input, Marshal.SizeOf(input[0]));
     }
     else
     {
         INPUT[] input = new INPUT[1];
         input[0].InputType = InputType.INPUT_MOUSE;
         input[0].mi.dwExtraInfo = GetMessageExtraInfo();
         input[0].mi.Flags = flags;
         input[0].mi.time = GetTickCount();
         input[0].mi.dx = (int)relX;
         input[0].mi.dy = (int)relY;
         input[0].mi.mouseData = mouseData;
         result = SendInput(1, input, Marshal.SizeOf(input[0]));
     }
     if (result == 0)
     {
         int err = Marshal.GetLastWin32Error();
         ("SendInput(mi) Blocked, 0x" + err.ToString("X")).Log();
     }
 }
コード例 #6
0
ファイル: SendKeyCmd.cs プロジェクト: RuneHL/MceController
 public static extern uint SendInput(uint nInputs, ref INPUT64 pInputs, int cbSize);
コード例 #7
0
ファイル: SendKeyCmd.cs プロジェクト: RuneHL/MceController
            public static void SendKeyUp(ushort key)
            {
                if (IntPtr.Size == 8)
                {
                    INPUT64 input64 = new INPUT64();
                    input64.type = INPUT_KEYBOARD;
                    input64.ki.wVk = key;
                    input64.ki.wScan = 0;
                    input64.ki.time = 0;
                    input64.ki.dwFlags = KEY_UP;
                    input64.ki.dwExtraInfo = IntPtr.Zero;

                    // Key up the actual key-code
                    SendInput64.SendInput(1, ref input64, Marshal.SizeOf(input64));
                }
                else
                {
                    INPUT32 input32 = new INPUT32();
                    input32.type = INPUT_KEYBOARD;
                    input32.ki.wVk = key;
                    input32.ki.wScan = 0;
                    input32.ki.time = 0;
                    input32.ki.dwFlags = KEY_UP;
                    input32.ki.dwExtraInfo = GetMessageExtraInfo();

                    // Key up the actual key-code
                    SendInput32.SendInput(1, ref input32, Marshal.SizeOf(input32));
                }
            }