I set global keyboard shortcuts on Windows using the RegisterHotKey method
public static int MOD_CONTROL = 0x2;
public static int WM_HOTKEY = 0x312;
RegisterHotKey(this.Handle, 0, MOD_CONTROL | MOD_NOREPEAT, 96);
Code for processing:
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_HOTKEY)
{
MessageBox.Show("a hotkey is pressed");
if (m.WParam.ToInt32() == 0)
{
MessageBox.Show("Hotkey ctrl numpad0 pressed");
}
}
base.WndProc(ref m);
}
On my Windows 7 PC, this works, but on XP or Windows Server 2003 it is not. Any ideas where this is going wrong?
source
share