public AddEditKeysDialog(ModulesConfiguration configuration, KeysInputVariable keys)
        {
            InitializeComponent();

            Array vals = Enum.GetValues(typeof(Microsoft.DirectX.DirectInput.Key));
            List <Microsoft.DirectX.DirectInput.Key> tmp = new List <Microsoft.DirectX.DirectInput.Key>();

            for (int i = 0; i < vals.Length; i++)
            {
                if (tmp.Contains((Microsoft.DirectX.DirectInput.Key)vals.GetValue(i)))
                {
                    continue;
                }
                tmp.Add((Microsoft.DirectX.DirectInput.Key)vals.GetValue(i));
                checkedListBox1.Items.Add(new KV()
                {
                    Key  = (Microsoft.DirectX.DirectInput.Key)vals.GetValue(i),
                    Name = Utils.KeyToFriendlyName((Microsoft.DirectX.DirectInput.Key)vals.GetValue(i))
                });
            }
            checkedListBox1.Sorted = true;

            _configuration = configuration;
            _keys          = keys;

            if (_keys != null)
            {
                Text                 = "Edycja klawiszy '" + _keys.ID + "'";
                textBox1.Text        = _keys.ID;
                textBox2.Text        = _keys.Description;
                checkBox1.Checked    = _keys.Repeat;
                numericUpDown1.Value = _keys.RepeatAfter;
                numericUpDown2.Value = _keys.RepeatInterval;
                for (int i = 0; i < _keys.Keys.Length; i++)
                {
                    for (int j = 0; j < checkedListBox1.Items.Count; j++)
                    {
                        if (((KV)checkedListBox1.Items[j]).Key == _keys.Keys[i])
                        {
                            checkedListBox1.SetItemChecked(j, true);
                            break;
                        }
                    }
                }
            }
            else
            {
                Text = "Dodaj klawisze";
            }

            textBox1.Focus();

            _defaultColor     = textBox3.BackColor;
            _defaultColorText = textBox3.ForeColor;

            _keyboard = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            _keyboard.SetDataFormat(Microsoft.DirectX.DirectInput.DeviceDataFormat.Keyboard);
            _keyboard.SetCooperativeLevel(IntPtr.Zero, Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive);
            _keyboard.Acquire();
        }
Example #2
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;
                }
            }
        }
Example #3
0
        //Gets a default mouse device
        public static Microsoft.DirectX.DirectInput.Device GetDefaultMouseDevice(System.Windows.Forms.Control control, int bufferSize)
        {
            Microsoft.DirectX.DirectInput.Device dev;
            dev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);

            dev.SetCooperativeLevel(control, Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Foreground | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive);
            dev.SetDataFormat(Microsoft.DirectX.DirectInput.DeviceDataFormat.Mouse);
            dev.Properties.BufferSize = bufferSize;

            try
            {
                dev.Acquire();
            }
            catch (Exception e)
            {
                throw new ExceptionDirectXAid(" Could not aquire default mouse device. Original exception: <<" + e.Message + ">>");
            }
            return(dev);
        }