private void OnExecuteVirtualKeyStroke(string partName, KeyStats keyStats) { if (!OnCanExecuteStringStroke(keyStats.Name)) { return; } switch (keyStats.KeyCode) { case KeysEx.VK_NUMLOCK: KeyboardLayout = (KeyboardLayout == KeyboardLayout.QuertyState ? KeyboardLayout.NumericState : KeyboardLayout.QuertyState); break; case KeysEx.VK_SHIFT: IsShiftPressed = !IsShiftPressed; break; case KeysEx.None: OnExecuteCustomKeyStroke(partName, keyStats); break; default: if (!keyStats.UseShift) { VirtualKeyboardService.Instance.ReleaseStickyKeys(); } if (keyStats.UseShift || IsShiftPressed) { VirtualKeyboardService.Instance.PressAndHold(KeysEx.VK_LSHIFT); } VirtualKeyboardService.Instance.PressAndRelease(keyStats.KeyCode); IsShiftPressed = false; break; } }
private void SendKeyStroke(string keyName, KeyStats keyStroke) { switch (KeyStrokeHandler) { case KeyboardKeyStrokeHandler.VirtualKeyboardBased: OnExecuteVirtualKeyStroke(keyName, keyStroke); break; case KeyboardKeyStrokeHandler.StringBased: OnExecuteStringStroke(keyName, keyStroke); break; } }
private void OnExecuteCustomKeyStroke(string partName, KeyStats keyStats) { switch (keyStats.Name) { case ".COM": VirtualKeyboardService.Instance.PressKey(KeysEx.VK_DECIMAL); VirtualKeyboardService.Instance.PressKey(KeysEx.VK_C); VirtualKeyboardService.Instance.PressKey(KeysEx.VK_O); VirtualKeyboardService.Instance.PressKey(KeysEx.VK_M); IsShiftPressed = false; VirtualKeyboardService.Instance.ReleaseStickyKeys(); break; default: break; } }
private void OnExecuteStringStroke(String partName, KeyStats keyStats) { var key = keyStats.Name; if (!OnCanExecuteStringStroke(key)) { return; } switch (key) { case "NumLock": KeyboardLayout = (KeyboardLayout == KeyboardLayout.QuertyState ? KeyboardLayout.NumericState : KeyboardLayout.QuertyState); break; case "Backspace": if (!String.IsNullOrEmpty(Text)) { // a quick hack to remove both \r AND \n Text = Text.EndsWith("\r\n") ? Text.Remove(Text.Length - 2) : Text.Remove(Text.Length - 1); } break; case "Shift": IsShiftPressed = !IsShiftPressed; break; case "Up": case "Left": case "Right": case "Down": break; default: if (Text != null && Text.Length >= MaxLength) { return; } Text += IsShiftPressed ? keyStats.Name : keyStats.ShiftName; IsShiftPressed = false; break; } }