private static void SendInput(byte[] oldKeyboardState, Queue previousEvents) { SendKeysR.AddCancelModifiersForPreviousEvents(previousEvents); NativeMethodsR.INPUT[] pInputs = new NativeMethodsR.INPUT[2]; pInputs[0].type = 1; pInputs[1].type = 1; pInputs[1].inputUnion.ki.wVk = (short)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 num1 = Marshal.SizeOf(typeof(NativeMethodsR.INPUT)); uint num2 = 0U; int count; lock (SendKeysR.events.SyncRoot) { bool local_4 = UnsafeNativeMethodsR.BlockInput(true); try { count = SendKeysR.events.Count; SendKeysR.ClearGlobalKeys(); for (int local_5 = 0; local_5 < count; ++local_5) { SendKeysR.SKEvent local_6 = (SendKeysR.SKEvent)SendKeysR.events.Dequeue(); pInputs[0].inputUnion.ki.dwFlags = 0; if (local_6.wm == 258) { pInputs[0].inputUnion.ki.wVk = (short)0; pInputs[0].inputUnion.ki.wScan = (short)local_6.paramL; pInputs[0].inputUnion.ki.dwFlags = 4; pInputs[1].inputUnion.ki.wScan = (short)local_6.paramL; num2 += UnsafeNativeMethodsR.SendInput(2U, pInputs, num1) - 1U; } else { pInputs[0].inputUnion.ki.wScan = (short)0; if (local_6.wm == 257 || local_6.wm == 261) pInputs[0].inputUnion.ki.dwFlags |= 2; if (SendKeysR.IsExtendedKey(local_6)) pInputs[0].inputUnion.ki.dwFlags |= 1; pInputs[0].inputUnion.ki.wVk = (short)local_6.paramL; num2 += UnsafeNativeMethodsR.SendInput(1U, pInputs, num1); SendKeysR.CheckGlobalKeys(local_6); } Thread.Sleep(1); } SendKeysR.ResetKeyboardUsingSendInput(num1); } finally { SendKeysR.SetKeyboardState(oldKeyboardState); if (local_4) UnsafeNativeMethodsR.BlockInput(false); } } if ((long)num2 != (long)count) throw new Win32Exception(); }
private static void ResetKeyboardUsingSendInput(int INPUTSize) { if (!SendKeysR.capslockChanged && !SendKeysR.numlockChanged && (!SendKeysR.scrollLockChanged && !SendKeysR.kanaChanged)) return; NativeMethodsR.INPUT[] pInputs = new NativeMethodsR.INPUT[2]; pInputs[0].type = 1; pInputs[0].inputUnion.ki.dwFlags = 0; pInputs[1].type = 1; pInputs[1].inputUnion.ki.dwFlags = 2; if (SendKeysR.capslockChanged) { pInputs[0].inputUnion.ki.wVk = (short)20; pInputs[1].inputUnion.ki.wVk = (short)20; int num = (int)UnsafeNativeMethodsR.SendInput(2U, pInputs, INPUTSize); } if (SendKeysR.numlockChanged) { pInputs[0].inputUnion.ki.wVk = (short)144; pInputs[1].inputUnion.ki.wVk = (short)144; int num = (int)UnsafeNativeMethodsR.SendInput(2U, pInputs, INPUTSize); } if (SendKeysR.scrollLockChanged) { pInputs[0].inputUnion.ki.wVk = (short)145; pInputs[1].inputUnion.ki.wVk = (short)145; int num = (int)UnsafeNativeMethodsR.SendInput(2U, pInputs, INPUTSize); } if (!SendKeysR.kanaChanged) return; pInputs[0].inputUnion.ki.wVk = (short)21; pInputs[1].inputUnion.ki.wVk = (short)21; int num1 = (int)UnsafeNativeMethodsR.SendInput(2U, pInputs, INPUTSize); }