Пример #1
0
        /// <summary>
        /// InputDevice constructor; registers the raw input devices
        /// for the calling window.
        /// </summary>
        /// <param name="hwnd">Handle of the window listening for key presses</param>
        public InputDevice(IntPtr hwnd)
        {
            //Create an array of all the raw input devices we want to
            //listen to. In this case, only keyboard devices.
            //RIDEV_INPUTSINK determines that the window will continue
            //to receive messages even when it doesn't have the focus.
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[2];

            rid[0].usUsagePage = 0x01;
            rid[0].usUsage     = 0x06;
            rid[0].dwFlags     = RIDEV_INPUTSINK;
            rid[0].hwndTarget  = hwnd;

            rid[1].usUsagePage = 0x01;
            rid[1].usUsage     = 0x02;
            rid[1].dwFlags     = RIDEV_INPUTSINK;
            rid[1].hwndTarget  = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[1])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #2
0
        public RawInput(IntPtr handle)
        {
            this.handle  = handle;
            mice         = new List <DeviceInfo>();
            keyboards    = new List <DeviceInfo>();
            otherDevices = new List <DeviceInfo>();

            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
            rid[0].usUsagePage = Win32RawInput.HID_HWIND.HidMouse.UsagePage;
            rid[0].usUsage     = Win32RawInput.HID_HWIND.HidMouse.UsageId;
            rid[0].dwFlags     = (int)RIDEV.INPUTSINK;
            rid[0].hwndTarget  = handle;

            if (!Win32RawInput.RegisterRawInputDevices(rid, rid.Length, Marshal.SizeOf(rid[0])))
            {
                throw new Win32Exception("Failed to register raw input device(s).");
            }

            int loadedDevices = LoadDevices();

            if (mice.Count <= 0)
            {
                throw new Win32Exception("Unable to detect an attached mouse");
            }
        }
Пример #3
0
        /// <summary>
        /// Creates new HID data reader.
        /// </summary>
        /// <param name="window">Window instance, which will reveice the WM_INPUT messages</param>
        public HidDataReader(Window window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            this.window         = window;
            this.window.Closed += this.OnWindowClosed;
            var handle = new WindowInteropHelper(this.window).Handle;
            var source = HwndSource.FromHwnd(handle);

            source.AddHook(this.WndProc);

            var devices = RawInputHelper.GetDevices();

            int i = 0;

            RAWINPUTDEVICE[] rids = new RAWINPUTDEVICE[devices.Count];

            // Setting handle to each rid device to receive the WM_INPUT message
            foreach (var device in devices)
            {
                rids[i].usUsagePage = device.UsagePage;
                rids[i].usUsage     = device.UsageCollection;
                rids[i].dwFlags     = RawInputDeviceFlags.RIDEV_INPUTSINK;
                rids[i].hwndTarget  = handle;
                i++;
            }

            this.handler             = new HidHandler(rids);
            this.handler.OnHidEvent += this.OnHidEvent;
        }
Пример #4
0
        /// <summary>
        ///   Register raw input device as defined and imported from our XML.
        /// </summary>
        /// <param name="aHWND"></param>
        public void Register(IntPtr aHWND)
        {
            var rid = new RAWINPUTDEVICE[_usageActions.Count];

            var i = 0;

            foreach (var entry in _usageActions)
            {
                rid[i].usUsagePage = entry.Value.UsagePage;
                rid[i].usUsage     = entry.Value.UsageCollection;
                rid[i].dwFlags     = (entry.Value.HandleHidEventsWhileInBackground ? Const.RIDEV_EXINPUTSINK : 0);
                rid[i].hwndTarget  = aHWND;
                i++;
            }

            var success = Function.RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0]));

            if (success)
            {
                Log.Info("HID: Raw input devices registration successful");
            }
            else
            {
                Log.Info("HID: Raw input devices registration failed");
            }
        }
Пример #5
0
        /// <summary>
        /// Add this KeyboardHook to a window
        /// </summary>
        /// <param name="window">The window to add to</param>
        internal void AddHook(System.Windows.Window window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            // 以下判断去掉是因为, 这会导致设置面板中不能选择并勾住后取消并选别的
            //if (mHwndSource != null)
            //  throw new InvalidOperationException("Hook already present");

            IntPtr hwnd = new WindowInteropHelper(window).Handle;

            mHwndSource = HwndSource.FromHwnd(hwnd);
            if (mHwndSource == null)
            {
                throw new ApplicationException("Failed to receive window source");
            }

            mHwndSource.AddHook(WndProc);

            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];

            rid[0].usUsagePage = 0x01;
            rid[0].usUsage     = 0x06;
            rid[0].dwFlags     = RIDEV_INPUTSINK;
            rid[0].hwndTarget  = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #6
0
        void CreateHandler()
        {
            int i = 0;

            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];



            rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.VirtualRealityControls;
            rid[i].usUsage     = (ushort)SharpLib.Hid.UsageCollection.VirtualReality.HeadTracker;
            rid[i].dwFlags     = RawInputDeviceFlags.RIDEV_EXINPUTSINK;
            rid[i].hwndTarget  = Handle;


            //i++;
            //rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
            //rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard;
            //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
            //rid[i].hwndTarget = Handle;

            //i++;
            //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
            //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse;
            //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
            //rid[i].hwndTarget = aHWND;

            iHandler = new SharpLib.Hid.Handler(rid);
            if (!iHandler.IsRegistered)
            {
                Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString());
            }

            iHandler.OnHidEvent += OnHidEvent;
        }
Пример #7
0
        /// <summary>
        /// InputDevice constructor; registers the raw input devices
        /// for the calling window.
        /// </summary>
        /// <param name="hwnd">Handle of the window listening for key presses</param>
        public InputDevice(IntPtr hwnd)
        {
            //Create an array of all the raw input devices we want to
            //listen to. In this case, only keyboard devices.
            //RIDEV_INPUTSINK determines that the window will continue
            //to receive messages even when it doesn't have the focus.
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[2];

            rid[0].usUsagePage = 0x01;
            rid[0].usUsage = 0x06;
            rid[0].dwFlags = RIDEV_INPUTSINK;
            rid[0].hwndTarget = hwnd;

            rid[1].usUsagePage = 0x01;
            rid[1].usUsage = 0x02;
            rid[1].dwFlags = RIDEV_INPUTSINK;
            rid[1].hwndTarget = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[1])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
        private void RegisterForRawInputDevices()
        {
            // register for raw input
            RAWINPUTDEVICE[] dev = new RAWINPUTDEVICE[1];

            dev[0].UsagePage    = HIDUsagePage.Generic;
            dev[0].Usage        = HIDUsage.Keyboard;
            dev[0].Flags        = 0;
            dev[0].WindowHandle = _source.Handle;

            var rv = RegisterRawInputDevices(dev, 1, Marshal.SizeOf(typeof(RAWINPUTDEVICE)));
        }
 public clsGetInputID(IntPtr hwnd)
 {
     RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
     rid[0].usUsagePage = 0x01;
     rid[0].usUsage     = 0x02;
     rid[0].dwFlags     = RIDEV_INPUTSINK;
     rid[0].hwndTarget  = hwnd;
     if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
     {
         throw new ApplicationException("Failed to register raw input device(s).");
     }
 }
Пример #10
0
        /// <summary>
        /// InputDevice constructor; registers the raw input device for the calling window
        /// </summary>
        /// <param name="hwnd">Handle of the window listening for events</param>
        public InputDevice(IntPtr hwnd)
        {
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
            rid[0].usUsagePage  = 0x01;
            rid[0].usUsage      = 0x04; // joystick
            rid[0].dwFlags      = RIDEV_INPUTSINK;
            rid[0].hwndTarget   = hwnd;

            if(!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device");
            }
        }
Пример #11
0
        public void RegisterMouse(IntPtr hwnd)
        {
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];

            rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;
            rid[0].usUsage     = HID_USAGE_GENERIC_MOUSE;
            rid[0].dwFlags     = RIDEV_INPUTSINK;
            rid[0].hwndTarget  = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #12
0
        /// <summary>
        /// InputDevice constructor; registers the raw input devices
        /// for the calling window.
        /// </summary>
        /// <param name="hwnd">Handle of the window listening for key presses</param>
        public _3DxMouse(IntPtr hwnd)
        {
            var rid = new RAWINPUTDEVICE[1];

            rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;
            rid[0].usUsage = HID_USAGE_GENERIC_MULTIAXIS_CONTROLLER;
            rid[0].dwFlags = RIDEV_INPUTSINK;
            rid[0].hwndTarget = hwnd;

            // Don't register each physical device, just the type (MultiAxis Controller)
            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #13
0
        public MainForm()
        {
            InitializeComponent();

            RAWINPUTDEVICE rawInputDevice = new RAWINPUTDEVICE(1, 6, API.RIDEV_INPUTSINK, this);
            bool ok = API.RegisterRawInputDevices(rawInputDevice);
            if(!ok) {
                throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            Debug.Assert(ok);

            WindowState = FormWindowState.Minimized;

            LoadDeviceList();
            LoadConfiguration();
        }
Пример #14
0
        public MainForm()
        {
            InitializeComponent();

            RAWINPUTDEVICE rawInputDevice = new RAWINPUTDEVICE(1, 6, API.RIDEV_INPUTSINK, this);
            bool           ok             = API.RegisterRawInputDevices(rawInputDevice);

            if (!ok)
            {
                throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            Debug.Assert(ok);

            WindowState = FormWindowState.Minimized;

            LoadConfiguration();
        }
Пример #15
0
        public void RegisterKeyboard(IntPtr hwnd, bool exclusive)
        {
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];

            rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;
            rid[0].usUsage     = 0x06;
            rid[0].dwFlags     = RIDEV_INPUTSINK;
            if (exclusive)
            {
                rid[0].dwFlags |= RIDEV_NOLEGACY;
            }
            rid[0].hwndTarget = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #16
0
        public void RegisterRawInputMouse(IntPtr hwnd)
        {
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
            rid[0].usUsagePage = 1;
            rid[0].usUsage = 2;
            rid[0].dwFlags = RIDEV_INPUTSINK;
            rid[0].hwndTarget = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                Debug.WriteLine("RegisterRawInputDevices() Failed");
            }

            //Debug.WriteLine("High Resolution Stopwatch: " + Stopwatch.IsHighResolution + "\n" +
            //                "Stopwatch TS: " + (1e6 / Stopwatch.Frequency).ToString() + " us\n" +
            //                "Stopwatch Hz: " + (Stopwatch.Frequency / 1e6).ToString() + " MHz\n");

            this.stopwatch_freq = 1e3 / Stopwatch.Frequency;
        }
Пример #17
0
            //-------------------------------------------------------------
            // constructors
            //-------------------------------------------------------------
            public RemoteControlDevice()
            {
                // Register the input device to receive the commands from the
                // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp
                // for the vendor defined usage page.

                var rid = new RAWINPUTDEVICE[3];

                rid[0].usUsagePage = 0xFFBC;
                rid[0].usUsage = 0x88;
                rid[0].dwFlags = 0;
                rid[0].hwndTarget = this.Handle;

                rid[1].usUsagePage = 0x0C;
                rid[1].usUsage = 0x01;
                rid[1].dwFlags = 0;
                rid[1].hwndTarget = this.Handle;

                rid[2].usUsagePage = 0x0C;
                rid[2].usUsage = 0x80;
                rid[2].dwFlags = 0;
                rid[2].hwndTarget = this.Handle;

                if (!RegisterRawInputDevices(rid,
                    (uint)rid.Length,
                    (uint)Marshal.SizeOf(rid[0]))
                    )
                {
                    Log.Warn("Failed to register raw input devices.");
                }
            }
Пример #18
0
        //-------------------------------------------------------------
        // constructors
        //-------------------------------------------------------------
        public MoreInfoHooker2()
        {
            this.CreateHandle(new CreateParams());
            _hookID = SetHook(_proc);
            kbHookID = SetKBHook(kbProc);
            // Register the input device to receive the commands from the
            // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp
            // for the vendor defined usage page.

            //RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[3];

            //rid[0].usUsagePage = 0xFFBC;
            //rid[0].usUsage = 0x88;
            //rid[0].dwFlags = 0;

            //rid[1].usUsagePage = 0x0C;
            //rid[1].usUsage = 0x01;
            //rid[1].dwFlags = 0;

            //rid[2].usUsagePage = 0x0C;
            //rid[2].usUsage = 0x80;
            //rid[2].dwFlags = 0;

            //if (!RegisterRawInputDevices(rid,
            //    (uint) rid.Length,
            //    (uint) Marshal.SizeOf(rid[0]))
            //    )
            //{
            //    throw new ApplicationException("Failed to register raw input devices.");
            //}

            RAWINPUTDEVICE[] pRawInputDevice = new RAWINPUTDEVICE[4];
            //pRawInputDevice[0].usUsagePage = 0xffbc;
            //pRawInputDevice[0].usUsage = 0x88;
            //pRawInputDevice[0].dwFlags = RIDEV.INPUTSINK;
            //pRawInputDevice[0].hwndTarget = base.Handle;
            //pRawInputDevice[1].usUsagePage = 12;
            //pRawInputDevice[1].usUsage = 1;
            //pRawInputDevice[1].dwFlags = RIDEV.INPUTSINK;
            //pRawInputDevice[1].hwndTarget = base.Handle;
            //pRawInputDevice[2].usUsagePage = 12;
            //pRawInputDevice[2].usUsage = 0x80;
            //pRawInputDevice[2].dwFlags = RIDEV.INPUTSINK;
            //pRawInputDevice[2].hwndTarget = base.Handle;
            //pRawInputDevice[3].usUsagePage = 1;
            //pRawInputDevice[3].usUsage = 6;
            //pRawInputDevice[3].dwFlags = RIDEV.INPUTSINK;
            //pRawInputDevice[3].hwndTarget = base.Handle;

            pRawInputDevice[0].usUsagePage = 0xFFBC;      // adds HID remote control
            pRawInputDevice[0].usUsage = 0x88;
            pRawInputDevice[0].dwFlags = RIDEV.INPUTSINK;
            pRawInputDevice[0].hwndTarget = base.Handle;

            pRawInputDevice[1].usUsagePage = 0x0C;      // adds HID remote control
            pRawInputDevice[1].usUsage = 0x01;
            pRawInputDevice[1].dwFlags = RIDEV.INPUTSINK;
            pRawInputDevice[1].hwndTarget = base.Handle;

            pRawInputDevice[2].usUsagePage = 0x0C;      // adds HID remote control
            pRawInputDevice[2].usUsage = 0x80;
            pRawInputDevice[2].dwFlags = RIDEV.INPUTSINK;
            pRawInputDevice[2].hwndTarget = base.Handle;

            //pRawInputDevice[3].usUsagePage = 0x01;      // adds HID mouse with no legacy messages
            //pRawInputDevice[3].usUsage = 0x02;
            //pRawInputDevice[3].dwFlags = RIDEV.NOLEGACY;
            ////pRawInputDevice[3].hwndTarget = base.Handle;

            pRawInputDevice[3].usUsagePage = 0x01;      // adds HID keyboard with no legacy message
            pRawInputDevice[3].usUsage = 0x06;
            pRawInputDevice[3].dwFlags = RIDEV.NOLEGACY;

            if (!RegisterRawInputDevices(pRawInputDevice, (uint)pRawInputDevice.Length, (uint)Marshal.SizeOf(pRawInputDevice[0])))
            {
                //throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
        public InputDevice(IntPtr hwnd, MainWindow mainWindow)
        {
            mMainWindow = mainWindow;

            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[2];

            rid[0].usUsagePage = HidUsagePage.GENERIC;
            rid[0].usUsage = HidUsage.Keyboard;
            rid[0].dwFlags = RawInputDeviceFlags.INPUTSINK;// | RawInputDeviceFlags.DEVNOTIFY;
            //rid[0].dwFlags = RawInputDeviceFlags.INPUTSINK;// | RawInputDeviceFlags.DEVNOTIFY;
            //rid[0].dwFlags = 0;
            rid[0].hwndTarget = hwnd;

            rid[1].usUsagePage = HidUsagePage.GENERIC;
            rid[1].usUsage = HidUsage.Mouse;
            rid[1].dwFlags = RawInputDeviceFlags.INPUTSINK;// | RawInputDeviceFlags.DEVNOTIFY;
            //rid[1].dwFlags = RawInputDeviceFlags.INPUTSINK;// | RawInputDeviceFlags.DEVNOTIFY;
            //rid[1].dwFlags = 0;
            rid[1].hwndTarget = hwnd;


            /*
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
            rid[0].usUsagePage = 0x01;
            rid[0].usUsage = 0x02;
            //rid[1].dwFlags = RIDEV_INPUTSINK;
            //rid[0].dwFlags = RIDEV_NOLEGACY;
            rid[0].dwFlags = 0;
            rid[0].hwndTarget = hwnd;
            */


            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #20
0
        public void RegisterMouse(IntPtr hwnd)
        {
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];

            rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;
            rid[0].usUsage = HID_USAGE_GENERIC_MOUSE;
            rid[0].dwFlags = RIDEV_INPUTSINK;
            rid[0].hwndTarget = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #21
0
        public void RegisterKeyboard(IntPtr hwnd, bool exclusive)
        {
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];

            rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;
            rid[0].usUsage = 0x06;
            rid[0].dwFlags = RIDEV_INPUTSINK;
            if (exclusive) rid[0].dwFlags |= RIDEV_NOLEGACY;
            rid[0].hwndTarget = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #22
0
    public static bool IsMceRemoteInstalled(IntPtr hwnd)
    {
      try
      {
        RAWINPUTDEVICE[] rid1 = new RAWINPUTDEVICE[1];

        rid1[0].usUsagePage = 0xFFBC;
        rid1[0].usUsage = 0x88;
        rid1[0].dwFlags = 0;
        rid1[0].hwndTarget = hwnd;
        bool Success = RegisterRawInputDevices(rid1, (uint)rid1.Length, (uint)Marshal.SizeOf(rid1[0]));
        if (Success)
        {
          return true;
        }

        rid1[0].usUsagePage = 0x0C;
        rid1[0].usUsage = 0x01;
        rid1[0].dwFlags = 0;
        rid1[0].hwndTarget = hwnd;
        Success = RegisterRawInputDevices(rid1, (uint)rid1.Length, (uint)Marshal.SizeOf(rid1[0]));
        if (Success)
        {
          return true;
        }
      }
      catch (Exception) {}

      return false;
    }
Пример #23
0
        public InputDevice(IntPtr hwnd)
        {
            hardwareId = ConfigurationManager.AppSettings["hardwareId"];
          
            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
            rid[0].usUsagePage = 0x01;
            rid[0].usUsage = 0x06;
            rid[0].dwFlags = RIDEV_INPUTSINK;
            rid[0].hwndTarget = hwnd;

            if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
Пример #24
0
    /// <summary>
    /// Register HID devices so that we receive corresponding WM_INPUT messages.
    /// </summary>
    protected void RegisterHidDevices(IntPtr aHwnd)
    {
      // Register the input device to receive the commands from the
      // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp
      // for the vendor defined usage page.

      RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];

      int i = 0;
      rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl;
      rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl;
      rid[i].dwFlags = RawInputDeviceFlags.RIDEV_INPUTSINK;
      rid[i].hwndTarget = aHwnd; //Process.GetCurrentProcess().MainWindowHandle;

      _hidHandler = new SharpLib.Hid.Handler(rid);
      if (!_hidHandler.IsRegistered)
      {
        Log.Write("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString());
      }
      _hidHandler.OnHidEvent += HandleHidEvent;
    }
     public static extern bool RegisterRawInputDevices(
   //[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
   //RAWINPUTDEVICE[] rawInputDevices,
   ref RAWINPUTDEVICE rawInputDevice,
   int deviceCount,
   int size
 );
Пример #26
0
        public MessageForm(MainForm mf)
        {
            this.mf = mf;

            //RAWINPUTDEVICE[] Rid = new RAWINPUTDEVICE[2];

            //Rid[0].UsagePage = 0xFFBC;
            //Rid[0].Usage = 0x88;
            //Rid[0].Flags = RawInputDeviceFlags.None;
            //Rid[0].WindowHandle = this.Handle;

            //Rid[1].UsagePage = 0x0C;
            //Rid[1].Usage = 0x01;
            //Rid[1].Flags = RawInputDeviceFlags.None;
            //Rid[1].WindowHandle = this.Handle;

            RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[3];

            rid[0].UsagePage = 0xFFBC;
            rid[0].Usage = 0x88;
            rid[0].Flags = RawInputDeviceFlags.None;

            rid[1].UsagePage = 0x0C;
            rid[1].Usage = 0x01;
            rid[1].Flags = RawInputDeviceFlags.None;

            rid[2].UsagePage = 0x0C;
            rid[2].Usage = 0x80;
            rid[2].Flags = RawInputDeviceFlags.None;

            if (!RegisterRawInputDevices(rid, rid.Length, Marshal.SizeOf(rid[0])))
            {
                FileLogger.Log("Couldn't register eHome remote");
            }
            else
            {
                FileLogger.Log("Registered eHome remote");
            }
        }
Пример #27
0
 internal static extern bool RegisterRawInputDevices(
   RAWINPUTDEVICE[] pRawInputDevice,
   uint uiNumDevices,
   uint cbSize);
Пример #28
0
        private bool registerMouse(IntPtr hWnd)
        {
            RAWINPUTDEVICE[] devices = new RAWINPUTDEVICE[1];

            devices[0].WindowHandle = hWnd;
            devices[0].UsagePage = HIDUsagePage.Generic;
            devices[0].Usage = HIDUsage.Mouse;
            devices[0].Flags = RawInputDeviceFlags.InputSink;

            return RegisterRawInputDevices(devices, 1, Marshal.SizeOf(typeof(RAWINPUTDEVICE)));
        }