/// <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); } }
/// <summary> /// 键抬起 /// </summary> /// <param name="key"></param> /// <param name="states"></param> public void SoftKeyUp(Key key, KeyStates states) { switch (key) { case Key.ImeProcessed: case Key.CapsLock: this.IsCapsLock = SoftKeyboardManager.GetState(Key.CapsLock); break; case Key.LeftShift: case Key.RightShift: this.IsShiftPressed = false; break; } }
/// <summary> /// 刷新键 /// 目前主要处理Caps、Shift等有状态的键 /// </summary> public void RefreshSoftKeys() { this.IsCapsLock = SoftKeyboardManager.GetState(Key.CapsLock); this.IsShiftPressed = (SoftKeyboardManager.GetState(Key.LeftShift) || SoftKeyboardManager.GetState(Key.RightShift)); }