Exemple #1
0
        private void ProcessingMethod()
        {
            Microsoft.DirectX.DirectInput.Device keyboard = null;
            try
            {
                // utworzenie obiektu do odczytywania stanu klawiatury
                keyboard = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
                keyboard.SetDataFormat(Microsoft.DirectX.DirectInput.DeviceDataFormat.Keyboard);
                keyboard.SetEventNotification(_event);
                keyboard.SetCooperativeLevel(IntPtr.Zero, Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive);
                keyboard.Acquire();

                while (_working)
                {
                    _event.WaitOne();
                    if (!_working)
                    {
                        break;
                    }
                    Microsoft.DirectX.DirectInput.KeyboardState state = keyboard.GetCurrentKeyboardState();
                    for (int i = 0; i < _spiesVariables.Length; i++)
                    {
                        _spiesVariables[i].CheckState(state);
                    }
                    _event.Reset();
                    if (!_working)
                    {
                        break;
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                _log.Log(this, ex.ToString());
            }
            finally
            {
                if (keyboard != null)
                {
                    try
                    {
                        keyboard.Unacquire();
                    }
                    catch { }
                    try
                    {
                        keyboard.Dispose();
                    }
                    catch { }
                    keyboard = null;
                }
            }
        }
 private void AddEditKeysDialog_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (_keyboard != null)
     {
         try
         {
             _keyboard.Unacquire();
         }
         catch { }
         try
         {
             _keyboard.Dispose();
         }
         catch { }
         _keyboard = null;
     }
 }