private void OnKeyTriggered(int keyCode) { int vKey1 = KeyInterop.VirtualKeyFromKey((Key)key1); int vKey2 = KeyInterop.VirtualKeyFromKey((Key)key2); if (keyCode == vKey2 && Win32Interop.IsKeyDown(vKey1)) { Win32Interop.ClickSimulateFocus(terminalWindow); Win32Interop.SetForegroundWindow(terminalWindow.Handle); Win32Interop.SetActiveWindow(terminalWindow.Handle); terminalWindow.Focus(); terminalWindow.Activate(); } }
private void KeyTriggered(int keyCode) { if (_key1 != null && _key2 != null) { int vKey1 = KeyInterop.VirtualKeyFromKey((Key)_key1); int vKey2 = KeyInterop.VirtualKeyFromKey((Key)_key2); if (keyCode == vKey2 && Win32Interop.IsKeyDown(vKey1)) { _terminalWindow.Input_TextBox.Text = ""; if (!_terminalWindowActive) { Win32Interop.ClickSimulateFocus(_terminalWindow); Win32Interop.SetForegroundWindow((new WindowInteropHelper(_terminalWindow)).Handle); Win32Interop.SetActiveWindow((new WindowInteropHelper(_terminalWindow)).Handle); FocusManager.SetFocusedElement(_terminalWindow, _terminalWindow.Input_TextBox); Keyboard.Focus(_terminalWindow.Input_TextBox); _terminalWindowActive = true; } else { _terminalWindowActive = false; Keyboard.ClearFocus(); } } } if (_awaitingKey1) { _key1 = KeyInterop.KeyFromVirtualKey(keyCode); _awaitingKey1 = false; Key1_Button.Content = _key1.ToString(); } if (_awaitingKey2) { _key2 = KeyInterop.KeyFromVirtualKey(keyCode); _awaitingKey2 = false; Key2_Button.Content = _key2.ToString(); } }