Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have always got a good performance by using <code>RegisterHotKey</code>/<code>UnregisterHotKey</code> functions. Sample code:</p> <pre><code>[DllImport("User32")] public static extern bool RegisterHotKey( IntPtr hWnd, int id, int fsModifiers, int vk ); [DllImport("User32")] public static extern bool UnregisterHotKey( IntPtr hWnd, int id ); public const int MOD_SHIFT = 0x4; public const int MOD_CONTROL = 0x2; public const int MOD_ALT = 0x1; public const int WM_HOTKEY = 0x312; protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY &amp;&amp; m.WParam == (IntPtr)0) { IntPtr lParamCTRLA = (IntPtr)4259842; IntPtr lParamB = (IntPtr)4325376; if (m.LParam == lParamCTRLA) { MessageBox.Show("CTRL+A was pressed"); } else if (m.LParam == lParamB) { MessageBox.Show("B was pressed"); } } base.WndProc(ref m); } private void Form1_Load(object sender, EventArgs e) { this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); RegisterHotKey(this.Handle, 0, MOD_CONTROL, (int)Keys.A); RegisterHotKey(this.Handle, 0, 0, (int)Keys.B); } private void Form1_FormClosing(Object sender, FormClosingEventArgs e) { UnregisterHotKey(this.Handle, 0); } </code></pre> <p>You can "register" as many keys (or combination of keys) as you want by emulating the shown structure. All the registered keys will get inside the condition <code>if (m.Msg == WM_HOTKEY &amp;&amp; m.WParam == (IntPtr)0)</code>; if they are pressed at all (independently upon the program currently being selected). The easiest way to know the specific key/combination being pressed is relying on <code>m.LParam</code> (I got the two values I am including after a quick test with the given keys). You can do a quick research to find out a list of <code>LParam</code> or further <code>constant</code> modifiers (wheel of the mouse, for example).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload