static void PressAKey(byte keycode) { //按键 SoftKeyboardManager.keybd_event(keycode, 0x45, SoftKeyboardManager.KEYEVENTF_EXTENDEDKEY | 0, 0); //释放按键 SoftKeyboardManager.keybd_event(keycode, 0x45, SoftKeyboardManager.KEYEVENTF_EXTENDEDKEY | SoftKeyboardManager.KEYEVENTF_KEYUP, 0); }
/// <summary> /// 设置具有状态的键的状态 /// </summary> /// <param name="key"></param> /// <param name="state"></param> public static void SetState(Key key, bool state) { if (state != SoftKeyboardManager.GetState(key)) { byte vkey = (byte)KeyInterop.VirtualKeyFromKey(key); SoftKeyboardManager.keybd_event(vkey, 69, 1u, 0u); SoftKeyboardManager.keybd_event(vkey, 69, 3u, 0u); } }