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(); }
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; } } }
//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); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here #if HAVE_LEGACY_DIRECTX Microsoft.DirectX.DirectInput.DeviceList dl = Microsoft.DirectX.DirectInput.Manager.GetDevices( Microsoft.DirectX.DirectInput.DeviceType.Joystick, Microsoft.DirectX.DirectInput.EnumDevicesFlags.AttachedOnly); while (dl.Count > 0 && dl.MoveNext()) { Microsoft.DirectX.DirectInput.DeviceInstance di = (Microsoft.DirectX.DirectInput.DeviceInstance)dl.Current; if (di.DeviceType == Microsoft.DirectX.DirectInput.DeviceType.Joystick) { //InitializeJoystick( di ); Console.WriteLine("DirectX joystick: {0}", di); // create a device from this controller. joystickDevice = new Microsoft.DirectX.DirectInput.Device(di.InstanceGuid); //joystickDevice.SetCooperativeLevel(this, // Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive); // Tell DirectX that this is a Joystick. joystickDevice.SetDataFormat(Microsoft.DirectX.DirectInput.DeviceDataFormat.Joystick); // Finally, acquire the device. joystickDevice.Acquire(); // Find the capabilities of the joystick Microsoft.DirectX.DirectInput.DeviceCaps cps = joystickDevice.Caps; // number of Axes Console.WriteLine("Joystick Axis: " + cps.NumberAxes); // number of Buttons Console.WriteLine("Joystick Buttons: " + cps.NumberButtons); // number of PoV hats Console.WriteLine("Joystick PoV hats: " + cps.NumberPointOfViews); break; } } #endif // Sound warsContent.SetContentManager(new ContentManager(this.Services, @"Content\")); //contentManager = new ContentManager(this.Services, @"Content\"); base.Initialize(); }