private static void ResetKeyboardUsingSendInput(int INPUTSize) { if ((capslockChanged || numlockChanged) || (scrollLockChanged || kanaChanged)) { System.Windows.Forms.NativeMethods.INPUT[] pInputs = new System.Windows.Forms.NativeMethods.INPUT[2]; pInputs[0].type = 1; pInputs[0].inputUnion.ki.dwFlags = 0; pInputs[1].type = 1; pInputs[1].inputUnion.ki.dwFlags = 2; if (capslockChanged) { pInputs[0].inputUnion.ki.wVk = 20; pInputs[1].inputUnion.ki.wVk = 20; UnsafeNativeMethods.SendInput(2, pInputs, INPUTSize); } if (numlockChanged) { pInputs[0].inputUnion.ki.wVk = 0x90; pInputs[1].inputUnion.ki.wVk = 0x90; UnsafeNativeMethods.SendInput(2, pInputs, INPUTSize); } if (scrollLockChanged) { pInputs[0].inputUnion.ki.wVk = 0x91; pInputs[1].inputUnion.ki.wVk = 0x91; UnsafeNativeMethods.SendInput(2, pInputs, INPUTSize); } if (kanaChanged) { pInputs[0].inputUnion.ki.wVk = 0x15; pInputs[1].inputUnion.ki.wVk = 0x15; UnsafeNativeMethods.SendInput(2, pInputs, INPUTSize); } } }
private static void SendInput(byte[] oldKeyboardState, Queue previousEvents) { int count; AddCancelModifiersForPreviousEvents(previousEvents); System.Windows.Forms.NativeMethods.INPUT[] pInputs = new System.Windows.Forms.NativeMethods.INPUT[2]; pInputs[0].type = 1; pInputs[1].type = 1; pInputs[1].inputUnion.ki.wVk = 0; pInputs[1].inputUnion.ki.dwFlags = 6; pInputs[0].inputUnion.ki.dwExtraInfo = IntPtr.Zero; pInputs[0].inputUnion.ki.time = 0; pInputs[1].inputUnion.ki.dwExtraInfo = IntPtr.Zero; pInputs[1].inputUnion.ki.time = 0; int cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.INPUT)); uint num2 = 0; lock (events.SyncRoot) { bool flag = UnsafeNativeMethods.BlockInput(true); try { count = events.Count; ClearGlobalKeys(); for (int i = 0; i < count; i++) { SKEvent skEvent = (SKEvent)events.Dequeue(); pInputs[0].inputUnion.ki.dwFlags = 0; if (skEvent.wm == 0x102) { pInputs[0].inputUnion.ki.wVk = 0; pInputs[0].inputUnion.ki.wScan = (short)skEvent.paramL; pInputs[0].inputUnion.ki.dwFlags = 4; pInputs[1].inputUnion.ki.wScan = (short)skEvent.paramL; num2 += UnsafeNativeMethods.SendInput(2, pInputs, cbSize) - 1; } else { pInputs[0].inputUnion.ki.wScan = 0; if ((skEvent.wm == 0x101) || (skEvent.wm == 0x105)) { pInputs[0].inputUnion.ki.dwFlags |= 2; } if (IsExtendedKey(skEvent)) { pInputs[0].inputUnion.ki.dwFlags |= 1; } pInputs[0].inputUnion.ki.wVk = (short)skEvent.paramL; num2 += UnsafeNativeMethods.SendInput(1, pInputs, cbSize); CheckGlobalKeys(skEvent); } Thread.Sleep(1); } ResetKeyboardUsingSendInput(cbSize); } finally { SetKeyboardState(oldKeyboardState); if (flag) { UnsafeNativeMethods.BlockInput(false); } } } if (num2 != count) { throw new Win32Exception(); } }
private static void SendInput(byte[] oldKeyboardState, Queue previousEvents) { int count; AddCancelModifiersForPreviousEvents(previousEvents); System.Windows.Forms.NativeMethods.INPUT[] pInputs = new System.Windows.Forms.NativeMethods.INPUT[2]; pInputs[0].type = 1; pInputs[1].type = 1; pInputs[1].inputUnion.ki.wVk = 0; pInputs[1].inputUnion.ki.dwFlags = 6; pInputs[0].inputUnion.ki.dwExtraInfo = IntPtr.Zero; pInputs[0].inputUnion.ki.time = 0; pInputs[1].inputUnion.ki.dwExtraInfo = IntPtr.Zero; pInputs[1].inputUnion.ki.time = 0; int cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.INPUT)); uint num2 = 0; lock (events.SyncRoot) { bool flag = UnsafeNativeMethods.BlockInput(true); try { count = events.Count; ClearGlobalKeys(); for (int i = 0; i < count; i++) { SKEvent skEvent = (SKEvent) events.Dequeue(); pInputs[0].inputUnion.ki.dwFlags = 0; if (skEvent.wm == 0x102) { pInputs[0].inputUnion.ki.wVk = 0; pInputs[0].inputUnion.ki.wScan = (short) skEvent.paramL; pInputs[0].inputUnion.ki.dwFlags = 4; pInputs[1].inputUnion.ki.wScan = (short) skEvent.paramL; num2 += UnsafeNativeMethods.SendInput(2, pInputs, cbSize) - 1; } else { pInputs[0].inputUnion.ki.wScan = 0; if ((skEvent.wm == 0x101) || (skEvent.wm == 0x105)) { pInputs[0].inputUnion.ki.dwFlags |= 2; } if (IsExtendedKey(skEvent)) { pInputs[0].inputUnion.ki.dwFlags |= 1; } pInputs[0].inputUnion.ki.wVk = (short) skEvent.paramL; num2 += UnsafeNativeMethods.SendInput(1, pInputs, cbSize); CheckGlobalKeys(skEvent); } Thread.Sleep(1); } ResetKeyboardUsingSendInput(cbSize); } finally { SetKeyboardState(oldKeyboardState); if (flag) { UnsafeNativeMethods.BlockInput(false); } } } if (num2 != count) { throw new Win32Exception(); } }