Question

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.

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top