public async Task ToggleAsync2() { for (var i = 0; i < 5; i++) { var Before = KeyboardState.Current()[KeyCode.LShift]; if (Before != KeyboardKeyState.Default) { await Simulate.Events().Release(KeyCode.LShift).Invoke(); } else { await Simulate.Events().Hold(KeyCode.LShift).Invoke(); } var After1 = KeyboardState.Current()[KeyCode.LShift]; var After2 = KeyboardState.Current()[KeyCode.LShift]; Console.WriteLine($@"Test {i}"); Console.WriteLine($@"Before: {Before}"); Console.WriteLine($@"After1: {After1}"); Console.WriteLine($@"After2: {After2}"); Console.WriteLine(); } }
public bool TryGetCharFromKeyboardState(KeyCode virtualKeyCode, int scanCode, ToUnicodeExFlags fuState, KeyboardLayout Layout, out string?chars) { chars = default; var Keyboard = KeyboardState.Current(); var isDead = false; if (Keyboard[KeyCode.LShift].IsDown() || Keyboard[KeyCode.RShift].IsDown()) { Keyboard[KeyCode.Shift] |= KeyboardKeyState.KeyDown; } if (Keyboard[KeyCode.CapsLock].IsToggled()) { Keyboard[KeyCode.CapsLock] |= KeyboardKeyState.Toggled; } //var ConversionStatus = ToUnicodeEx((KeyCode)virtualKeyCode, scanCode, currentKeyboardState, pwszBuff, pwszBuff.Capacity, fuState, Layout.Handle); var ConversionStatus = ToUnicodeEx(Layout, Keyboard, fuState, virtualKeyCode, scanCode, out var Characters); switch (ConversionStatus) { case ToUnicodeExStatus.DeadKey: isDead = true; ClearKeyboardBuffer(virtualKeyCode, scanCode, Layout); break; case ToUnicodeExStatus.NoTranslation: break; case ToUnicodeExStatus.Success: chars = Characters; break; } if (lastVirtualKeyCode == 0 || !lastIsDead) { lastScanCode = scanCode; lastVirtualKeyCode = virtualKeyCode; lastIsDead = isDead; lastKeyState = Keyboard.Clone(); } else if (chars is {})
public static IObservable <KeyWithState> WithState(this IObservable <KeyCode> source) { return(source .Select(evt => new KeyWithState(evt, KeyboardState.Current()))); }