In WPF is it possible to trigger an event if say the keyboard right or left directions are pressed, now matter which control has focus?
No matter where in the form has focus or what they are doing I need something to happen if Right Or Left is hit.
Is it absolutely necessary to track down every keyboard notification (KeyDown and KeyUp events)?
Edit:
For more info, I have a slider that I need to be controlled by left and right buttons at any time. I also have a combobox that I need to open. I tried using this code, but it stops me from using the combobox:
Private Sub sldDays_IsKeyboardFocusedChanged(sender As Object, e As System.Windows.DependencyPropertyChangedEventArgs) Handles sldDays.IsKeyboardFocusedChanged
Keyboard.Focus(sldDays)
End Sub
Edit 2:
In case anyone stumbles on this in the future I think I solved my issue:
I set this method to the PreviewKeyDown Event (this makes it always go first as the key down)
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
PreviewKeyDown="sliderKey"
Then this is the event:
Private Sub sliderKey(sender As System.Object, e As KeyEventArgs)
Try
If e.Key = Key.Right Then
sldDays.Value += 1
ElseIf e.Key = Key.Left Then
sldDays.Value -= 1
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub