Exemple #1
0
 public void CaptureHostDevice(string hostId)
 {
     try
     {
         if (hostId == string.Empty)
         {
             return;
         }
         if (hostId == KeyboardNumpadId)
         {
             IsKeyboardStateRequired = true;
             return;
         }
         using (var di = new DirectInput8W())
         {
             var list = di.EnumDevices(DI8DEVCLASS.GAMECTRL, DIEDFL.ATTACHEDONLY);
             foreach (var deviceInstance in list)
             {
                 if (string.Compare(
                         GetDeviceId(deviceInstance.guidInstance),
                         hostId,
                         true) != 0)
                 {
                     continue;
                 }
                 var joystick = di.CreateDevice(deviceInstance.guidInstance, null);
                 try
                 {
                     joystick.SetDataFormat(DIDATAFORMAT.c_dfDIJoystick).CheckError();
                     //joystick.SetCooperativeLevel(_hwnd, DISCL.BACKGROUND | DISCL.NONEXCLUSIVE).CheckError();
                     // someone replaced hwnd with null to fix app close hung (when MDX was used)
                     joystick.SetCooperativeLevel(IntPtr.Zero, DISCL.BACKGROUND | DISCL.NONEXCLUSIVE).CheckError();
                     joystick.Acquire().CheckError();
                     _devices.Add(hostId, joystick);
                 }
                 catch (Exception ex)
                 {
                     Logger.Error(ex);
                     joystick.Dispose();
                     continue;
                 }
                 ActivateDevice(hostId);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
     }
 }
Exemple #2
0
        public unsafe DirectMouse(Form form)
        {
            _form = form;
            _hWnd = form.Handle;
            if (_device == null)
            {
                using (var dinput = new DirectInput8W())
                {
                    _device = dinput.CreateDevice(SysGuid.GUID_SysMouse, null);
                }
                _device.SetDataFormat(DIDATAFORMAT.c_dfDIMouse).CheckError();

                form.Deactivate += WndDeactivate;
            }
        }
Exemple #3
0
 public unsafe DirectKeyboard(Form form)
 {
     if (form == null)
     {
         throw new ArgumentNullException("form");
     }
     _form = form;
     _hWnd = form.Handle;
     using (var dinput = new DirectInput8W())
     {
         _device = dinput.CreateDevice(SysGuid.GUID_SysKeyboard, null);
     }
     _device.SetDataFormat(DIDATAFORMAT.c_dfDIKeyboard).CheckError();
     _device.SetCooperativeLevel(_hWnd, DISCL.NONEXCLUSIVE | DISCL.FOREGROUND).CheckError();
     form.Deactivate += WndDeactivate;
     TryAcquire();
     _mapper.LoadMapFromString(
         global::ZXMAK2.Host.WinForms.Properties.Resources.Keyboard_Mdx);
 }