Вопрос

I want to detect when a combination like Ctrl-C is pressed in a WPF application. What I've read online says to use something like the following in the KeyDown (or KeyUp) Event:

if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S))
{
    MessageBox.Show("Save!");
}

I'm just trying to understand how this works. As I understand it, e.Key contains the key that was pressed that triggered the event and Keyboard.Modifiers contains the information about the state of the Control key right now. Is it safe to assume that the Control key will still be down by the time the KeyDown event gets handled?

For example, I restart Firefox and it grinds away loading a bunch of tabs, and in the meantime I hit Ctrl-S in my application. There is a delay in getting to KeyDown, and the application thinks just S has been pressed.

Thanks

Это было полезно?

Решение

You could use KeyBindings instead, they define full gestures without such a separation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top