I created a WPF application, where if the user press ctl + alt + s, I need to focus the text field of the WPF application.
Example: if you press ctl + w, the website will automatically open.
Thanks in advance.
Use InputBindings , define a KeyBinding and create a command that focuses.
<Window.InputBindings> <KeyBinding Command="{Binding MyFocusCommand}" Key="S" Modifiers="Control+Alt"/> </Window.InputBindings>
You can subscribe to the PreviewKeyDown event:
PreviewKeyDown
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Alt) && e.Key == Key.S) { textBox1.Focus(); } }
You can achieve this using a hook with a low-level keyboard
http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx