/// <summary> /// ctor and init /// </summary> /// <param name="device">A DXInput device</param> /// <param name="hwnd">The WinHandle of the main window</param> public MouseCls(SharpDX.DirectInput.Mouse device, Control hwnd) { log.DebugFormat("MouseCls cTor - Entry with {0}", device.Information.ProductName); m_device = device; m_hwnd = hwnd; Activated_low = false; m_senseLimit = AppConfiguration.AppConfig.msSenseLimit; // can be changed in the app.config file if it is still too little // Set BufferSize in order to use buffered data. m_device.Properties.BufferSize = 128; log.Debug("Get Mouse Object"); try { // Set the data format to the c_dfDIJoystick pre-defined format. //m_device.SetDataFormat( DeviceDataFormat.Joystick ); // Set the cooperative level for the device. m_device.SetCooperativeLevel(m_hwnd, CooperativeLevel.NonExclusive | CooperativeLevel.Background); // Enumerate all the objects on the device. } catch (Exception ex) { log.Error("Get Mouse Object failed", ex); } MouseCls.RegisteredDevices++; Activated_low = true; }
public override Action Start() { IntPtr handle = Process.GetCurrentProcess().MainWindowHandle; mouseDevice = new SharpDX.DirectInput.Mouse(directInputInstance); if (mouseDevice == null) { throw new Exception("Failed to create mouse device"); } mouseDevice.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); mouseDevice.Properties.AxisMode = DeviceAxisMode.Relative; // Get delta values mouseDevice.Acquire(); getPressedStrategy = new GetPressedStrategy <int>(IsDown); setPressedStrategy = new SetPressedStrategy <int>(SetButtonDown, SetButtonUp); OnStarted(this, new EventArgs()); return(null); }
private void _initializeInputs() { Console.Write("Initializing inputs... "); _directInput = ToDispose<DirectInput>(new DirectInput()); _dKeyboard = ToDispose<DKeyboard>(new DKeyboard(_directInput)); _dKeyboard.Properties.BufferSize = 256; _dKeyboard.SetCooperativeLevel(_form, CooperativeLevel.Foreground | CooperativeLevel.Exclusive); Keyboard = new Keyboard(_dKeyboard); _dMouse = ToDispose<DMouse>(new DMouse(_directInput)); _dMouse.Properties.AxisMode = DeviceAxisMode.Relative; _dMouse.SetCooperativeLevel(_form, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive); Mouse = new Mouse(_form, _dMouse); Console.WriteLine("done."); }