I want to use a Shortcut in a Windows Form App and found the following code.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == (Keys.Enter)) {
MessageBox.Show("Hello World!");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
But this only works, if the window is active. How can I use the shortcut even if a different window is active?
You could use a single entry point for message catching and dispatching in a base form.
Base Form
Base Form Descendant
Edit - Global KeyboardHook
If you are looking to trap all key events in other applications then you will need to use a Keyboard Hook. Here is a nice article describing using
SetWindowsHookEx
.