Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when a hotkey (shortcut key) is pressed

How do I detect when a shortcut key such as Ctrl + O is pressed in a WPF (independently of any particular control)?

I tried capturing KeyDown but the KeyEventArgs doesn't tell me whether or not Control or Alt is down.

like image 415
Qwertie Avatar asked May 06 '09 22:05

Qwertie


1 Answers

private void Window_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
    {
        // CTRL is down.
    }
}
like image 90
JP Alioto Avatar answered Sep 28 '22 15:09

JP Alioto