private void RunDriverThread() { //create and init _rmInput = new RawMouseInput(); if (_rmInput == null) { MessageBox.Show("ERROR: could not create rawinput class"); } _driverWindow = new DriverWindow(_rmInput); if (_driverWindow == null) { MessageBox.Show("ERROR: could not create driverwindow class");//error } _rmInput.RegisterForWM_INPUT(_driverWindow.Handle); _filter = new PreMessageFilter(); if (_filter == null) { MessageBox.Show("ERROR: could not add premessage filter"); //error } Application.AddMessageFilter(_filter); Application.Run(_driverWindow); Application.RemoveMessageFilter(_filter); if (_driverWindow.IsDisposed == false) { _driverWindow.Dispose(); } _driverWindow = null; _rmInput = null; }
public void AddMessageFilter() { if (null != filter) return; filter = new PreMessageFilter(); Application.AddMessageFilter(filter); }
public override void AddMessageFilter() { if (_filter != null) { return; } _filter = new PreMessageFilter(this); Application.AddMessageFilter(_filter); }
public void AddMessageFilter() { if (null != _filter) { return; } _filter = new PreMessageFilter(); Application.AddMessageFilter(_filter); }
internal void ConnectRawInput() { IntPtr formHandle = view.FormHandle; keyboardDriver = new KeyboardDriver(formHandle); EnumerateDevices(); // Register for device notifications. devNotifyHandle = IntPtr.Zero; BroadcastDeviceInterface bdi = new BroadcastDeviceInterface(); bdi.Size = Marshal.SizeOf(bdi); bdi.BroadcastDeviceType = BroadcastDeviceType.DBT_DEVTYP_DEVICEINTERFACE; bdi.ClassGuid = deviceInterfaceHid; IntPtr mem = IntPtr.Zero; try { mem = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BroadcastDeviceInterface))); Marshal.StructureToPtr(bdi, mem, false); devNotifyHandle = Win32.RegisterDeviceNotification(formHandle, mem, DeviceNotification.DEVICE_NOTIFY_WINDOW_HANDLE); } catch (Exception e) { Debug.Print("Registration for device notifications Failed. Error: {0}", Marshal.GetLastWin32Error()); Debug.Print(e.StackTrace); } finally { Marshal.FreeHGlobal(mem); } if (devNotifyHandle == IntPtr.Zero) { Debug.Print("Registration for device notifications Failed. Error: {0}", Marshal.GetLastWin32Error()); } // Adding a message filter will cause keypresses to be handled. if (preMessageFilter == null) { preMessageFilter = new PreMessageFilter(); Application.AddMessageFilter(preMessageFilter); } keyboardDriver.KeyPressed += OnKeyPressed; foreach (KeyPressEvent device in keyboardDriver.DeviceList.Values) { view.AddComboBoxItem(device); } }
/// <summary> /// Create a new driverwindow and register that window to receive WM_INPUT messages from RawMouseInput /// </summary> private void RunDriverThread() { // Create and initialise array of all rawmice _rmInput = new RawMouseInput(); if (_rmInput == null) { MessageBox.Show("ERROR: could not create rawinput class"); } // Create driver window to receive WM_INPUT messages try { _driverWindow = new InputCaptureWindow(_rmInput); } catch (Exception e) {; } if (_driverWindow == null) { MessageBox.Show("ERROR: could not create driverwindow class"); } // Register the window to receive raw input _rmInput.RegisterForWM_INPUT(_driverWindow.Handle); // Create a message filter _filter = new PreMessageFilter(); if (_filter == null) { MessageBox.Show("ERROR: could not add premessage filter"); } // Apply the filter Application.AddMessageFilter(_filter); // Load the form and begin the main message pump loop Application.Run(_driverWindow); // FOLLOWING LINES ONLY EXECUTE WHEN driverWindow EXITS! // Remove the message filter Application.RemoveMessageFilter(_filter); // Clean up if (_driverWindow.IsDisposed == false) { _driverWindow.Dispose(); } _driverWindow = null; _rmInput = null; }