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(); }
void init() { Microsoft.DirectX.Direct3D.PresentParameters pps = new Microsoft.DirectX.Direct3D.PresentParameters(); pps.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard; pps.Windowed = true; pps.BackBufferCount = 1; pps.PresentationInterval = PresentInterval.One; pps.BackBufferFormat = Format.A8R8G8B8; if (GameWindow == null) { //pps.BackBufferWidth = GameControl.Width; //pps.BackBufferHeight = GameControl.Height; D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameControl, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps); } else { //pps.BackBufferWidth = GameWindow.Width; //pps.BackBufferHeight = GameWindow.Height; D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameWindow, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps); } D3DDev.VertexFormat = CustomVertex.PositionColoredTextured.Format; //D3DDev.ShowCursor(false); DSoundDev = new Microsoft.DirectX.DirectSound.Device(); if (GameWindow == null) { DSoundDev.SetCooperativeLevel(GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal); } else { DSoundDev.SetCooperativeLevel(GameWindow, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal); } DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard); DKeyboardDev.Acquire(); DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse); DMouseDev.Acquire(); VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), 6, D3DDev, Usage.None, CustomVertex.PositionColoredTextured.Format, Pool.Managed); D3DDev.SetStreamSource(0, VertexBuffer, 0); D3DDev.TextureState[0].AlphaOperation = TextureOperation.Modulate; Sprite = new Sprite(D3DDev); FontDescription fd = new FontDescription(); fd.FaceName = "新宋体"; fd.Height = -12; Font2D = new Microsoft.DirectX.Direct3D.Font(D3DDev, fd); Font3D = new System.Drawing.Font("新宋体", 12); }
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; } } }
public GamePad(string scenePattern) { InitializeComponent(); this.scenePatternName = scenePattern; engine = new Engine(this); engine.OnTurnedOn += this.Init; engine.TurnOn(); keyboard = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard); //keyboard.SetCooperativeLevel(this, Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Exclusive); keyboard.Acquire(); }
//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(); }
void init() { Microsoft.DirectX.Direct3D.PresentParameters pps = new Microsoft.DirectX.Direct3D.PresentParameters(); pps.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard; pps.Windowed = true; pps.BackBufferCount = 1; pps.PresentationInterval = PresentInterval.One; pps.BackBufferFormat = Format.A8R8G8B8; if (GameWindow == null) { //pps.BackBufferWidth = GameControl.Width; //pps.BackBufferHeight = GameControl.Height; D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameControl, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps); } else { //pps.BackBufferWidth = GameWindow.Width; //pps.BackBufferHeight = GameWindow.Height; D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameWindow, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps); } D3DDev.VertexFormat = CustomVertex.PositionColoredTextured.Format; //D3DDev.ShowCursor(false); DSoundDev = new Microsoft.DirectX.DirectSound.Device(); if (GameWindow == null) { DSoundDev.SetCooperativeLevel(GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal); } else { DSoundDev.SetCooperativeLevel(GameWindow, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal); } DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard); DKeyboardDev.Acquire(); DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse); DMouseDev.Acquire(); VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), 6, D3DDev, Usage.None, CustomVertex.PositionColoredTextured.Format, Pool.Managed); D3DDev.SetStreamSource(0, VertexBuffer, 0); D3DDev.TextureState[0].AlphaOperation = TextureOperation.Modulate; Sprite = new Sprite(D3DDev); FontDescription fd = new FontDescription(); fd.FaceName = "新宋体"; fd.Height = -12; Font2D = new Microsoft.DirectX.Direct3D.Font(D3DDev, fd); Font3D = new System.Drawing.Font("新宋体", 12); }