Focus window wpf on the shortcut key

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.

+4
source share
3 answers

Use InputBindings , define a KeyBinding and create a command that focuses.

<Window.InputBindings> <KeyBinding Command="{Binding MyFocusCommand}" Key="S" Modifiers="Control+Alt"/> </Window.InputBindings> 
+3
source

You can subscribe to the PreviewKeyDown event:

 private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Alt) && e.Key == Key.S) { textBox1.Focus(); } } 
+2
source

You can achieve this using a hook with a low-level keyboard

http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx

+1
source

All Articles