Reputation: 20406
I have created a WPF application, where if user press ctl + alt + s, my WPF application textbox needs to be focused.
Example: if you press ctl+w, automatically word web will get focused.
Thanks in advance.
Upvotes: 4
Views: 2566
Reputation: 7958
You can achive this by using low level keyboard hook
http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx
Upvotes: 1
Reputation: 184296
Use InputBindings, define a KeyBinding and create a command which does the focusing.
<Window.InputBindings>
<KeyBinding Command="{Binding MyFocusCommand}" Key="S" Modifiers="Control+Alt"/>
</Window.InputBindings>
Upvotes: 3
Reputation: 78447
You can subscribe to PreviewKeyDown
event:
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Alt) &&
e.Key == Key.S)
{
textBox1.Focus();
}
}
Upvotes: 2