title: Capturing a key without focusing the window
body: <p>I have a application that always checks if a key like <kbd>F12</kbd> is pressed. It doesn't need to have in focus of my main window of my app. I tried this code:</p>
  
  <pre><code>public int a = 1;
      // DLL libraries used to manage hotkeys
      [DllImport("user32.dll")]
      public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
      [DllImport("user32.dll")]
      public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
  
      const int MYACTION_HOTKEY_ID = 1;
  
      public Form1()
      {
          InitializeComponent();
          // Modifier keys codes: Alt = 1, Ctrl = 2, Shift = 4, Win = 8
          // Compute the addition of each combination of the keys you want to be pressed
          // ALT+CTRL = 1 + 2 = 3 , CTRL+SHIFT = 2 + 4 = 6...
          RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 0, (int) Keys.F12);
      }
  
      protected override void WndProc(ref Message m)
      {
          if (m.Msg == 0x0312 &amp;&amp; m.WParam.ToInt32() == MYACTION_HOTKEY_ID)
          {
  
              a++;
              MessageBox.Show(a.ToString());
          }
          base.WndProc(ref m);
      }
  </code></pre>
  
  <p>I put 0 to this line <code>RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 0, (int) Keys.F12);</code> so that only if <kbd>F12</kbd> is pressed it will capture.</p>
  
  <p>But it didn't work. How can I solve this?</p>
  
  <p>Here I couldn't understand some lines like:</p>
  
  <pre><code>const int MYACTION_HOTKEY_ID = 1;
  m.Msg == 0x0312 &amp;&amp; m.WParam.ToInt32() == MYACTION_HOTKEY_ID
  base.WndProc(ref m);
  </code></pre>
  
  <p>Can anyone help me to understand these lines?</p>