Exemple #1
0
        public static Thread MouseListenerThread(OnDeviceEvent onDeviceEventCallback, string deviceIdFilter = null)
        {
            Thread mouseListenerThread = new Thread(() =>
            {
                var mouse    = new RawInputReceiverWindow();
                mouse.Input += (sender, e) =>
                {
                    if (deviceIdFilter != e.Data.Header.DeviceHandle.ToString())
                    {
                        return;
                    }
                    onDeviceEventCallback(e.Data);
                };

                try
                {
                    // Register the HidUsageAndPage to watch any device.
                    RawInputDevice.RegisterDevice(HidUsageAndPage.Mouse, RawInputDeviceFlags.ExInputSink, mouse.Handle);
                    Application.Run();
                }
                finally
                {
                    RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);
                }
            });

            mouseListenerThread.Priority = ThreadPriority.Highest;
            mouseListenerThread.Start();
            return(mouseListenerThread);
        }
Exemple #2
0
        private void OnDisable()
        {
            RawInputWindowProcedure.Instance.ReceiveRawInput -= OnReceiveRawInput;
#if UNITY_EDITOR
            Debug.Log("RawInputDevice.UnregisterDevice was skipped in editor");
#else
            RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);
#endif
        }
Exemple #3
0
    protected virtual void Dispose(bool disposing)
    {
        _source?.RemoveHook(MessageSink);

        RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard);
        RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);

        _source = null;
    }
Exemple #4
0
 private void Main_FormClosing(object sender, FormClosingEventArgs e)
 {
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Joystick);
     //RawInputDevice.UnregisterDevice(HidUsageAndPage.GamePad);
     if (port != null)
     {
         if (port.IsOpen)
         {
             port.WriteLine("M106 S0");
             port.WriteLine("M18");
             port.Close();
         }
     }
 }
Exemple #5
0
        public static Thread JoystickListenerThread(OnDeviceEvent onDeviceEventCallback, string deviceIdFilter = null)
        {
            Thread joystickListenerThread = new Thread(() =>
            {
                var joystick = new RawInputReceiverWindow();
                RawInputData previousMessage = null;
                joystick.Input += (sender, e) =>
                {
                    if (deviceIdFilter != e.Data.Header.DeviceHandle.ToString())
                    {
                        return;
                    }
                    if (previousMessage?.ToString() == e.Data.ToString())
                    {
                        return;
                    }
                    dynamic dataObject = e.Data;
                    if (dataObject.Hid.Count > 1)
                    {
                        return;
                    }
                    previousMessage = e.Data;
                    onDeviceEventCallback(e.Data);
                };

                try
                {
                    // Register the HidUsageAndPage to watch any device.
                    RawInputDevice.RegisterDevice(HidUsageAndPage.Joystick, RawInputDeviceFlags.ExInputSink, joystick.Handle);
                    Application.Run();
                }
                finally
                {
                    RawInputDevice.UnregisterDevice(HidUsageAndPage.Joystick);
                }
            });

            joystickListenerThread.Priority = ThreadPriority.Highest;
            joystickListenerThread.Start();
            return(joystickListenerThread);
        }
Exemple #6
0
 private void Disconn_Click(object sender, EventArgs e)
 {
     try
     {
         if (port != null)
         {
             if (port.IsOpen)
             {
                 port.WriteLine("M106 S0");
                 port.WriteLine("M18");
                 port.Close();
                 messageBx.Text += "com port sucessfully closed";
             }
         }
     }
     catch (Exception ex)
     {
         messageBx.Text += "Error Closing serial port :: " + ex.Message + "Error!";
     }
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Joystick);
 }
Exemple #7
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Setup INI file and create it if nessesary.
            string iniFilePath = $"{Application.StartupPath}\\config.ini";

            if (File.Exists(iniFilePath) == false)
            {
                File.Create(iniFilePath).Close();
            }
            INIFile = new INIFile(iniFilePath);

            InputWindow = new RawInputWindow();
            // RawInputDevice.RegisterDevice(HidUsageAndPage.TouchPad, RawInputDeviceFlags.ExInputSink, InputWindow.Handle);
            RawInputDevice.RegisterDevice(HidUsageAndPage.Joystick, RawInputDeviceFlags.ExInputSink, InputWindow.Handle);

            MainWindow = new MainWindow();
            Application.Run(MainWindow);

            RawInputDevice.UnregisterDevice(HidUsageAndPage.GamePad);
        }
Exemple #8
0
        static void Main()
        {
            // Get the devices that can be handled with Raw Input.
            var devices = RawInputDevice.GetDevices();

            // Keyboards will be returned as a RawInputKeyboard.
            var keyboards = devices.OfType <RawInputKeyboard>();

            // List them up.
            foreach (var device in keyboards)
            {
                Console.WriteLine($"{device.DeviceType} {device.VendorId:X4}:{device.ProductId:X4} {device.ProductName}, {device.ManufacturerName}");
            }

            // To begin catching inputs, first make a window that listens WM_INPUT.
            var window = new RawInputReceiverWindow();

            window.Input += (sender, e) =>
            {
                // Catch your input here!
                var data = e.Data;

                Console.WriteLine(data);
            };

            try
            {
                // Register the HidUsageAndPage to watch any device.
                RawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard, RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.NoLegacy, window.Handle);

                Application.Run();
            }
            finally
            {
                RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard);
            }
        }
Exemple #9
0
        public static Thread KeyboardListenerThread(OnDeviceEvent onDeviceEventCallback, string deviceIdFilter = null)
        {
            Thread keyboardListenerThread = new Thread(() =>
            {
                var keyboard = new RawInputReceiverWindow();
                RawInputData previousMessage = null;
                keyboard.Input += (sender, e) =>
                {
                    if (deviceIdFilter != e.Data.Header.DeviceHandle.ToString())
                    {
                        return;
                    }
                    if (previousMessage?.ToString() == e.Data.ToString())
                    {
                        return;
                    }
                    previousMessage = e.Data;
                    onDeviceEventCallback(e.Data);
                };

                try
                {
                    // Register the HidUsageAndPage to watch any device.
                    RawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard, RawInputDeviceFlags.ExInputSink, keyboard.Handle);
                    Application.Run();
                }
                finally
                {
                    RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard);
                }
            });

            keyboardListenerThread.Priority = ThreadPriority.Highest;
            keyboardListenerThread.Start();
            return(keyboardListenerThread);
        }
 public void StopListening()
 {
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard);
     _source?.RemoveHook(WndProcHook);
 }
Exemple #11
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);
 }
Exemple #12
0
 private static void Clean(object sender, EventArgs e)
 {
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);
 }
 private void MainWindow_FormClosed(object sender, FormClosedEventArgs e)
 {
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard);
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);
     trayIcon.Visible = false;
 }
Exemple #14
0
 private void MainWindow_FormClosed(object sender, FormClosedEventArgs e)
 {
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);
 }
Exemple #15
0
        static async Task Main(string[] args)
        {
            // To begin catching inputs, first make a window that listens WM_INPUT.
            var window = new RawInputReceiverWindow();

            // Build the IPC Pipe
            var Client = new CommonCommunication.Client();

            // Create the event handler
            window.Input += async(sender, e) =>
            {
                // ECVILLA Device
                if (e.Data.Device.DevicePath == @"\\?\HID#VID_0C45&PID_760A&MI_00#b&22a65cf9&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}")
                {
                    if (false == Client.IsConnected())
                    {
                        // Connect to IPC service
                        Console.WriteLine($"Connecting to elite_keyboard");

                        await Client.CreateConnection("elite_keyboard").ConfigureAwait(false);

                        Console.WriteLine($"Connected to elite_keyboard");
                    }

                    if (e.Data is RawInputKeyboardData)
                    {
                        var keyboardData = e.Data as RawInputKeyboardData;

                        var messageBody = new EliteJoystick.Common.Messages.KeyboardMessage
                        {
                            VirutalKey = keyboardData.Keyboard.VirutalKey,
                            ScanCode   = keyboardData.Keyboard.ScanCode,
                            Flags      = (int)keyboardData.Keyboard.Flags
                        };

                        var message = new CommonCommunication.Message
                        {
                            Type = "keypress",
                            Data = JsonConvert.SerializeObject(messageBody)
                        };

                        // Send the message to the IPC channel
                        await Client.SendMessageAsync(JsonConvert.SerializeObject(message)).ConfigureAwait(false);

                        Console.WriteLine($"{e.Data.Device.DevicePath}: {e.Data}");
                    }
                }
            };

            try
            {
                // Register the HidUsageAndPage to watch any device.
                RawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard, RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.NoLegacy, window.Handle);

                Console.WriteLine($"Ready");

                // Run the listener
                Application.Run();
            }
            finally
            {
                RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard);
            }
        }
 public static void Unhook()
 {
     receiver?.ReleaseHandle();
     RawInputDevice.UnregisterDevice(HidUsageAndPage.Mouse);
 }