I have a simple WPF application and I need to capture F1 key pressed in Windows (Operation System), even if my WPF window is minimized, or it isn't activated.
I have problems with detecting this. I searched on Internet and I found many results, but they didn't helped me.
For detecting a key pressed inside of application I used this simple code:
AddHandler(Keyboard.KeyDownEvent, (KeyEventHandler)KeyPressed);
private void KeyPressed(object sender, KeyEventArgs e)
{
if (e.Key == Key.F1)
{
//my code went here
}
}
But this doesn't work when my window isn't activated.
So, my question is: how to detect global key press?
I repeat: It is a WPF application.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…