Exemple #1
0
        internal void RegisterRawInputDevices()
        {
            NativeMethods.RAWINPUTDEVICE[] devices = new NativeMethods.RAWINPUTDEVICE[3];

            // for TouchScreen
            devices[0].usUsagePage = 0x0D; //Digitizer
            devices[0].usUsage     = 0x04; //Touch Screen
            devices[0].hwndTarget  = ownerWmInputMessageReceivingWindowHandle;
            devices[0].dwFlags     = (int)NativeMethods.RIDEV.INPUTSINK;

            // for Mouse
            devices[1].usUsagePage = 0x01; //Generic Desktop
            devices[1].usUsage     = 0x02; //Mouse
            devices[1].hwndTarget  = ownerWmInputMessageReceivingWindowHandle;
            devices[1].dwFlags     = (int)NativeMethods.RIDEV.INPUTSINK;

            // for VSC TouchScreen (VSC=Vendor SpeCific)
            devices[2].usUsagePage = 0xFF00; //Vendor
            devices[2].usUsage     = 0x01;   //Vendor (Touch Screen)
            devices[2].hwndTarget  = ownerWmInputMessageReceivingWindowHandle;
            devices[2].dwFlags     = (int)NativeMethods.RIDEV.INPUTSINK;

            // devices.Length: The number of "WM_INPUT enabled" devices
            int size = Marshal.SizeOf(typeof(NativeMethods.RAWINPUTDEVICE));

            NativeMethods.RegisterRawInputDevices(devices, (uint)devices.Length, (uint)size);
        }
        private void RegisterDevices()
        {
            NativeMethods.RAWINPUTDEVICE[] rid = new NativeMethods.RAWINPUTDEVICE[1];

            rid[0].usUsagePage = NativeMethods.TouchScreenUsagePage;
            rid[0].usUsage     = 0x04;
            rid[0].dwFlags     = NativeMethods.RIDEV_INPUTSINK | NativeMethods.RIDEV_DEVNOTIFY;
            rid[0].hwndTarget  = Handle;

            if (!NativeMethods.RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
        /// <summary>
        /// Registers ourselves to listen to raw input from keyboard-like devices.
        /// </summary>
        /// <param name="hwnd">the handle of the form that will receive the raw
        /// input messages</param>
        /// <exception cref="InvalidOperationException">if the call to register with the
        /// raw input API fails for some reason</exception>
        private static void HookRawInput(IntPtr hwnd)
        {
            NativeMethods.RAWINPUTDEVICE[] rid;

            rid = new NativeMethods.RAWINPUTDEVICE[1];

            rid[0].usUsagePage = 0x01;      // USB HID Generid Desktop Page
            rid[0].usUsage     = 0x06;      // Keyboard Usage ID
            rid[0].dwFlags     = NativeMethods.RawInputDeviceFlags.RIDEV_INPUTSINK;
            rid[0].hwndTarget  = hwnd;

            if (!NativeMethods.RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                InvalidOperationException e;

                e = new InvalidOperationException(
                    "The barcode scanner listener could not register for raw input devices.",
                    new Win32Exception());
                throw e;
            }
        }
        private void RegisterDevices()
        {
            NativeMethods.RAWINPUTDEVICE[] rid = new NativeMethods.RAWINPUTDEVICE[1];

            rid[0].usUsagePage = NativeMethods.TouchScreenUsagePage;
            rid[0].usUsage = 0x04;
            rid[0].dwFlags = NativeMethods.RIDEV_INPUTSINK;
            rid[0].hwndTarget = Handle;

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