Note that there are some explanatory texts on larger screens.

plurals
  1. POIn WPF how do you detect a key press/down event at any point
    primarykey
    data
    text
    <p>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?</p> <p>No matter where in the form has focus or what they are doing I need something to happen if Right Or Left is hit.</p> <p>Is it absolutely necessary to track down every keyboard notification (KeyDown and KeyUp events)?</p> <p><strong>Edit:</strong> </p> <p>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:</p> <pre><code>Private Sub sldDays_IsKeyboardFocusedChanged(sender As Object, e As System.Windows.DependencyPropertyChangedEventArgs) Handles sldDays.IsKeyboardFocusedChanged Keyboard.Focus(sldDays) End Sub </code></pre> <p><strong>Edit 2:</strong></p> <p>In case anyone stumbles on this in the future I think I solved my issue:</p> <p>I set this method to the PreviewKeyDown Event (this makes it always go first as the key down)</p> <pre><code>&lt;Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" PreviewKeyDown="sliderKey" </code></pre> <p>Then this is the event:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload