title: C# RawInputDevice in Windows: How I can disable messages for all applications except my?
body: <p>I have a RawInputDevice that I registered. </p>
  
  <pre><code>// sample
  private void SplashLoad(object sender, EventArgs e)
          {
              var rid = new RawInputDevice[1];
              rid[0].UsagePage = HidUsagePage.GENERIC;
              rid[0].Usage = HidUsage.Keyboard;
              rid[0].Flags = RawInputDeviceFlags.INPUTSINK;
              rid[0].Target = Handle;
              if (!Win32.RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
              {
                  throw new ApplicationException("Не удалось зарегистрировать устройство.");
              }
              inputBuffer = "";
              this.terminateFlag = false;
              t = new Thread(MainThread);
              t.Start(this);
          }
  // another cs file goes there
      internal enum RawInputDeviceFlags
          {
              /// &lt;summary&gt;No flags.&lt;/summary&gt;
              NONE = 0,
              /// &lt;summary&gt;If set, this removes the top level collection from the inclusion list. This tells the operating system to stop reading from a device which matches the top level collection.&lt;/summary&gt;
              REMOVE = 0x00000001,
              /// &lt;summary&gt;If set, this specifies the top level collections to exclude when reading a complete usage page. This flag only affects a TLC whose usage page is already specified with PageOnly.&lt;/summary&gt;
              EXCLUDE = 0x00000010,
              /// &lt;summary&gt;If set, this specifies all devices whose top level collection is from the specified UsagePage. Note that Usage must be zero. To exclude a particular top level collection, use Exclude.&lt;/summary&gt;
              PAGEONLY = 0x00000020,
              /// &lt;summary&gt;If set, this prevents any devices specified by UsagePage or Usage from generating legacy messages. This is only for the mouse and keyboard.&lt;/summary&gt;
              NOLEGACY = 0x00000030,
              /// &lt;summary&gt;If set, this enables the caller to receive the input even when the caller is not in the foreground. Note that WindowHandle must be specified.&lt;/summary&gt;
              INPUTSINK = 0x00000100,
              /// &lt;summary&gt;If set, the mouse button click does not activate the other window.&lt;/summary&gt;
              CAPTUREMOUSE = 0x00000200,
              /// &lt;summary&gt;If set, the application-defined keyboard device hotkeys are not handled. However, the system hotkeys; for example, ALT+TAB and CTRL+ALT+DEL, are still handled. By default, all keyboard hotkeys are handled. NoHotKeys can be specified even if NoLegacy is not specified and WindowHandle is NULL.&lt;/summary&gt;
              NOHOTKEYS = 0x00000200,
              /// &lt;summary&gt;If set, application keys are handled.  NoLegacy must be specified.  Keyboard only.&lt;/summary&gt;
              APPKEYS = 0x00000400,
              /// If set, this enables the caller to receive input in the background only if the foreground application
              /// does not process it. In other words, if the foreground application is not registered for raw input,
              /// then the background application that is registered will receive the input.
              /// &lt;/summary&gt;
              EXINPUTSINK = 0x00001000,
              DEVNOTIFY = 0x00002000
          }
  
          public enum HidUsagePage : ushort
          {
              /// &lt;summary&gt;Unknown usage page.&lt;/summary&gt;
              UNDEFINED = 0x00,
              /// &lt;summary&gt;Generic desktop controls.&lt;/summary&gt;
              GENERIC = 0x01,
              /// &lt;summary&gt;Simulation controls.&lt;/summary&gt;
              SIMULATION = 0x02,
              /// &lt;summary&gt;Virtual reality controls.&lt;/summary&gt;
              VR = 0x03,
              /// &lt;summary&gt;Sports controls.&lt;/summary&gt;
              SPORT = 0x04,
              /// &lt;summary&gt;Games controls.&lt;/summary&gt;
              GAME = 0x05,
              /// &lt;summary&gt;Keyboard controls.&lt;/summary&gt;
              KEYBOARD = 0x07,
          }
  
          public enum HidUsage : ushort
          {
              /// &lt;summary&gt;Unknown usage.&lt;/summary&gt;
              Undefined = 0x00,
              /// &lt;summary&gt;Pointer&lt;/summary&gt;
              Pointer = 0x01,
              /// &lt;summary&gt;Mouse&lt;/summary&gt;
              Mouse = 0x02,
              /// &lt;summary&gt;Joystick&lt;/summary&gt;
              Joystick = 0x04,
              /// &lt;summary&gt;Game Pad&lt;/summary&gt;
              Gamepad = 0x05,
              /// &lt;summary&gt;Keyboard&lt;/summary&gt;
              Keyboard = 0x06,
              /// &lt;summary&gt;Keypad&lt;/summary&gt;
              Keypad = 0x07,
              /// &lt;summary&gt;Muilt-axis Controller&lt;/summary&gt;
              SystemControl = 0x80,
              /// &lt;summary&gt;Tablet PC controls&lt;/summary&gt;
              Tablet = 0x80,
              /// &lt;summary&gt;Consumer&lt;/summary&gt;
              Consumer = 0x0C,
          }
  </code></pre>
  
  <p>That device - card scanner, is HID that emulating keyboard in system. All works but I have problem: messages from device goes no only for my app (that works in the background, in the tray) but to active window app too. How I can disable that and set message available only for my app?</p>