There is a post to set system-wide global hotkey in C# here
I want to set application-wide hotkey such that if user presses a hotkey on any child window of an application, a particular window will receive and process it.
Thanks.
You can create a base form for your application and set keypreview property to true and handle keydown event so all your forms will have the same key definition.
You also can use the following routine to register a hotkey for your forms but in this method, you will require to call same method on load event of each form.
protected override bool ProcessCmdKey(ref Message message, Keys keys)
{
switch (keys)
{
case Keys.F2 | Keys.Control:
//Process action here.
return false;
}
return false;
}
You also can use the following unmanaged methods from user32.dll but of course i would not suggest that.
static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint virtualKey);
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With