If you want to detect a key pressed only in our application (when the WPF window is activated), add KeyDownas shown below:
public MainWindow()
{
InitializeComponent();
this.KeyDown += new KeyEventHandler(MainWindow_KeyDown);
}
void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("You pressed a keyboard key.");
}
If you want to detect when a key is pressed, even your WPF window is not active, it is a little more complicated, but positive. I recommend RegisterHotKey(defines a hotkey for the entire system) UnregisterHotKeyfrom the Windows API. Try using them in C # from pinvoke.net or these tutorials:
Thse - Microsoft.
.
, , .