public void ResetModifiersAsNeeded(int scanCode) { // If called from same thread if (InvokeRequired == false) { // we called ourself by creating async caller ResetModifiersAsNeededMethod d = new ResetModifiersAsNeededMethod(ResetModifiersAsNeeded); d.BeginInvoke(scanCode, null, null); return; } // we are in seperated thread, sleep and wait System.Threading.Thread.Sleep(50); int[] autoResetVKs = new int[] { (int)NativeMethods.VK.LCONTROL, (int)NativeMethods.VK.RCONTROL, (int)NativeMethods.VK.LMENU, (int)NativeMethods.VK.RMENU, (int)NativeMethods.VK.LSHIFT, (int)NativeMethods.VK.RSHIFT }; int[] autoResetScanCodes = new int[] { 0x2A, 0x36, 0x1D, 0x38, 0xE038, 0xE01D }; if (!autoResetScanCodes.Contains(scanCode)) { foreach (int vkey in autoResetVKs) { if ((NativeMethods.GetAsyncKeyState(vkey) & 0x8000) == 0x8000) { SendInput.SendSingleVK((ushort)vkey, NativeMethods.KEYEVENTF.KEYUP); } } } }
public void ResetModifiersAsNeeded(int scanCode) { // If called from same thread if (InvokeRequired == false) { // we called ourself by creating async caller ResetModifiersAsNeededMethod d = new ResetModifiersAsNeededMethod(ResetModifiersAsNeeded); d.BeginInvoke(scanCode, null, null); return; } // we are in seperated thread, sleep and wait System.Threading.Thread.Sleep(50); int[] autoResetVKs = new int[] { (int)NativeMethods.VK.LCONTROL, (int)NativeMethods.VK.RCONTROL, (int)NativeMethods.VK.LMENU, (int)NativeMethods.VK.RMENU, (int)NativeMethods.VK.LSHIFT, (int)NativeMethods.VK.RSHIFT }; int[] autoResetScanCodes = new int[] { 0x2A, 0x36, 0x1D, 0x38, 0xE038, 0xE01D }; if (!autoResetScanCodes.Contains(scanCode)) { foreach (int vkey in autoResetVKs) { if ((NativeMethods.GetAsyncKeyState(vkey) & 0x8000) == 0x8000) { SendInput.SendSingleVK((ushort)vkey, NativeMethods.KEYEVENTF.KEYUP); } } } }