/// <summary> /// Získání prvního gamepadu, ketrý je připojený k počítači /// </summary> /// <returns>zařízení</returns> /// <exception>Pokud se nepodařilo najít žádné funkční zařízení</exception> private SlimDX.DirectInput.Joystick getGamepad() { dinput = new DirectInput(); SlimDX.DirectInput.Joystick gamepad; string errorMessage = "Nebylo nalezeno žádné vnější ovládací zařízení."; foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)) { try { gamepad = new SlimDX.DirectInput.Joystick(dinput, device.InstanceGuid); gamepad.Acquire(); foreach (DeviceObjectInstance deviceObject in gamepad.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) { gamepad.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100); } } return gamepad; } catch (DirectInputException e) { dinput.Dispose(); errorMessage = e.Message; } } dinput.Dispose(); throw new DirectInputException(errorMessage); }
public void Dispose() { device?.Dispose(); device = null; directInput?.Dispose(); directInput = null; }
public static int NumJoysticks() { DirectInput direct = new DirectInput(); int count = direct.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly).Count; direct.Dispose(); return count; }
public void Dispose() { keyboardDevice?.Dispose(); keyboardDevice = null; directInput?.Dispose(); directInput = null; }
public void Dispose() { enabled = false; task.Wait(); keyboard?.Dispose(); direct?.Dispose(); }
private void ConfigEditDialog_FormClosing(object sender, FormClosingEventArgs e) { directInput?.Dispose(); directInput = null; inputDevice?.Dispose(); inputDevice = null; }
public void Dispose() { if (_pollingTask.Status == TaskStatus.Running) { StopCapture(); } _directInput?.Dispose(); //_joystick?.Dispose(); }
public static void Init(Form mainWindow) { var dinput = new DirectInput(); _keyboard = new Keyboard(dinput); _keyboard.Acquire(); _mouse = new Mouse(dinput); _mouse.Acquire(); dinput.Dispose(); dinput = null; }
public static void Cleanup() { lock (_lockObj) { _keyboard?.Dispose(); _keyboard = null; _directInput?.Dispose(); _directInput = null; } }
/// <summary> データを読み取っている場合、それを停止する </summary> public void Stop() { LogOutput.Instance.Write("Stop Reading Gamepad"); _joystick?.Dispose(); _joystick = null; _directInput?.Dispose(); _directInput = null; _joystickReady = false; }
protected override void Cleanup() { _subsysKeyboard?.Dispose(); _subsysKeyboard = null; _subsysMouse?.Dispose(); _subsysMouse = null; di?.Dispose(); di = null; base.Cleanup(); }
public void Shutdown() { _mouse?.Unacquire(); _mouse?.Dispose(); _mouse = null; // Release the keyboard. _keyboard?.Unacquire(); _keyboard?.Dispose(); _keyboard = null; // Release the main interface to direct input. _directInput?.Dispose(); _directInput = null; }
public override void Dispose() { // Dispose all the gamepads foreach (var pair in Devices) { var gameController = pair.Value as GameControllerDirectInput; gameController?.Dispose(); } // Unregisters all devices base.Dispose(); // Dispose DirectInput directInput.Dispose(); }
public override void Stop() { if (mouseDevice != null) { mouseDevice.Unacquire(); mouseDevice.Dispose(); mouseDevice = null; } if (directInputInstance != null) { directInputInstance.Dispose(); directInputInstance = null; } }
public static void Cleanup() { lock (_syncObj) { foreach (var device in _devices) { device.joystick.Dispose(); } _devices.Clear(); if (_dinput != null) { _dinput.Dispose(); _dinput = null; } } }
public static void cleanUp() { diDev.Dispose(); if (forceFeedbackEnabled) { afterburnerEffect.Dispose(); gForceEffect.Dispose(); cruiseMissileEffect.Dispose(); fireEffect.Dispose(); hitEffect.Dispose(); } if (JSDevice != null) { JSDevice.Dispose(); } m_input.Dispose(); }
/// <summary> /// Отключение /// </summary> public void Disconnect() { try { lock (_threadLock) { _quitThread = true; } _joystickThread.Join(); _joystick.Unacquire(); _joystick.Dispose(); _directInput.Dispose(); } catch (Exception) { } }
public static void Cleanup() { lock (SyncObj) { if (_keyboard != null) { _keyboard.Dispose(); _keyboard = null; } if (_directInput != null) { _directInput.Dispose(); _directInput = null; } } }
/// <summary> /// デバイスに接続して読み取れる状態にする。 /// </summary> /// <param name="mainWindowHandle"></param> public void ConnectToDevice(IntPtr mainWindowHandle) { LogOutput.Instance.Write("Connect to Gamepad.."); Stop(); _directInput = new DirectInput(); //使えそうなゲームパッド or ジョイスティックを探す //FirstPersonが最初なのは暗黙にDUAL SHOCK 4の優先度を上げるため。 //(手元環境だとDUAL SHOCK 4はなぜかFirstPersonにヒットする) //他のGamepadとかだとフットペダルみたいなのが先に引っかかることがあるので、それを予防してます。 //またGameControlは「拾いすぎ」になりやすいんだけど、これは仕方ないということで今は許容します var devices = _directInput.GetDevices(DeviceType.FirstPerson, DeviceEnumerationFlags.AllDevices) .Concat(_directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) .Concat(_directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) .Concat(_directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices)) .ToList(); if (devices.Count == 0) { LogOutput.Instance.Write("No Gamepad Found"); _directInput?.Dispose(); _directInput = null; return; } var joystickGuid = devices[0].InstanceGuid; _joystick = new Joystick(_directInput, joystickGuid); LogOutput.Instance.Write("Gamepad Found, name = " + _joystick.Properties.ProductName); try { //初期設定: バックグラウンドで非占有にすることで常時読み取れるようにする //CAUTION: コントローラによってはこの設定を無視する。例えばXBox OneコントローラはForegroundじゃないとダメ。 _joystick.SetCooperativeLevel(mainWindowHandle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); _joystick.Acquire(); _joystickReady = true; } catch (Exception ex) { LogOutput.Instance.Write(ex); } }
public static void Cleanup() { lock (SyncObj) { foreach (var device in Devices) { device._joystick.Dispose(); } Devices.Clear(); if (_directInput != null) { _directInput.Dispose(); _directInput = null; } } }
// The bulk of the clean-up code is implemented in Dispose(bool) protected virtual void Dispose(bool disposing) { if (disposing) { Stop(); UnInitDeviceDetector(); TimerSemaphore.Dispose(); if (Manager != null) { Manager.Dispose(); Manager = null; } if (_timer != null) { _timer.Dispose(); } } }
// Disposer public void Dispose() { // Not already disposed? if (!isdisposed) { // Dispose mouse.Unacquire(); mouse.Dispose(); dinput.Dispose(); // Clean up mouse = null; dinput = null; // Done isdisposed = true; } }
public void Finish() { if (_keyboard != null) { _keyboard.Unacquire(); _keyboard.Dispose(); _keyboard = null; } if (_dinput != null) { _dinput.Dispose(); _dinput = null; } if (_timer != null) { _timer.Stop(); _timer = null; } }
public void StopCapture() { if (pollingThread != null) { pollingThread.Abort(); // wait until thread finishes pollingThread.Join(); } if (joystick != null) { joystick.Dispose(); } if (directInput != null) { directInput.Dispose(); } }
public void Finish() { if (_joystick != null) { _joystick.Unacquire(); _joystick.Dispose(); _joystick = null; } if (_dinput != null) { _dinput.Dispose(); _dinput = null; } if (_timer != null) { _timer.Stop(); _timer = null; } }
/// <summary> /// デバイスに接続して読み取れる状態にする。 /// </summary> /// <param name="mainWindowHandle"></param> public void ConnectToDevice(IntPtr mainWindowHandle) { LogOutput.Instance.Write("Connect to Gamepad.."); Stop(); _directInput = new DirectInput(); //使えそうなゲームパッド or ジョイスティックを探す //Gamepad, Joystick, どっちも無ければGameControlクラスを順に探します var devices = _directInput .GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices) .Concat(_directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) .Concat(_directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices)) .ToList(); if (devices.Count == 0) { LogOutput.Instance.Write("No Gamepad Found"); _directInput?.Dispose(); _directInput = null; return; } var joystickGuid = devices[0].InstanceGuid; _joystick = new Joystick(_directInput, joystickGuid); LogOutput.Instance.Write("Gamepad Found, name = " + _joystick.Properties.ProductName); try { //初期設定: バックグラウンドで非占有にすることで常時読み取れるようにする //CAUTION: コントローラによってはこの設定を無視する。例えばXBox OneコントローラはForegroundじゃないとダメ。 _joystick.SetCooperativeLevel(mainWindowHandle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); _joystick.Acquire(); _joystickReady = true; } catch (Exception ex) { LogOutput.Instance.Write(ex); } }
protected void Dispose(bool disposing) { if (!_isDisposed) { /* * The following text is from MSDN (http://msdn.microsoft.com/en-us/library/fs2xkftw%28VS.80%29.aspx) * Dispose(bool disposing) executes in two distinct scenarios: * If disposing equals true, the method has been called directly or indirectly by a user's code and managed and unmanaged resources can be disposed. * If disposing equals false, the method has been called by the runtime from inside the finalizer and only unmanaged resources can be disposed. * When an object is executing its finalization code, it should not reference other objects, because finalizers do not execute in any particular order. * If an executing finalizer references another object that has already been finalized, the executing finalizer will fail. */ if (disposing) { // Unregister events // get rid of managed resources if (_directInput != null) { _directInput.Dispose(); } if (_keyboard != null) { _keyboard.Dispose(); } if (_mouse != null) { _mouse.Dispose(); } if (_joystick1 != null) { _joystick1.Dispose(); } } // get rid of unmanaged resources } }
public void Shutdown() { if (_keyboard != null) { _keyboard.Unacquire(); _keyboard.Dispose(); _keyboard = null; } if (_mouse != null) { _mouse.Unacquire(); _mouse.Dispose(); _mouse = null; } if (_directInput != null) { _directInput.Dispose(); _directInput = null; } }
//----------------------------------------------------------------------- public override void Stop() { // Don't leave any keys pressed for (int i = 0; i < MyKeyDown.Length; i++) { if (MyKeyDown[i]) { KeyUp(i); } } if (KeyboardDevice != null) { KeyboardDevice.Unacquire(); KeyboardDevice.Dispose(); KeyboardDevice = null; } if (DirectInputInstance != null) { DirectInputInstance.Dispose(); DirectInputInstance = null; } }
public override void Dispose() { mDIobject.Dispose(); }
public void Dispose() { _directInput.Dispose(); }
static EntryField() { TKKeys = Enum.GetValues(typeof(TKKey)).Cast <TKKey>().ToList(); TKButtons = Enum.GetValues(typeof(XInputGamePadButton)).Cast <XInputGamePadButton>().ToList(); TKKeysHeld = new HashSet <TKKey>(); TKButtonsHeld = TKButtons.ToDictionary(b => b, b => false); TKButtonsInitialState = new Dictionary <int, Dictionary <XInputGamePadButton, bool?> >(); var inputPoll = new Timer(50); inputPoll.Elapsed += (sender, args) => { var inputPressed = false; try { var keyState = TKKeyboard.GetState(); if (keyState.IsConnected) { foreach (var key in TKKeys) { if (keyState.IsKeyDown(key)) { if (!TKKeysHeld.Contains(key)) { OnTKKeyPress(key); } TKKeysHeld.Add(key); inputPressed = true; } else { TKKeysHeld.Remove(key); } } } } catch { } if (CreateController()) { var buttons = CaptureControllerInput(); if (DXButtonInitialState == null) { DXButtonInitialState = buttons.Cast <bool?>().ToArray(); } for (int i = 0; buttons != null && i < buttons.Length; i++) { if (buttons[i] != DXButtonInitialState[i]) { DXButtonInitialState[i] = null; } if (DXButtonInitialState[i] == null) { if (buttons[i]) { if (!DXButtonsHeld[i]) { OnButtonPress(i); } DXButtonsHeld[i] = true; inputPressed = true; } else { DXButtonsHeld[i] = false; } } } } for (int i = 0; i <= 3; i++) { var isFirstRun = TKButtonsInitialState.Count <= i || TKButtonsInitialState[i] == null; if (isFirstRun) { TKButtonsInitialState[i] = new Dictionary <XInputGamePadButton, bool?>(); } var initialState = TKButtonsInitialState[i]; try { var gamePadState = GamePad.GetState(i); if (gamePadState.IsConnected) { foreach (var button in TKButtons) { var buttonIsPressed = gamePadState.IsPressed(button); if (isFirstRun) { initialState.TryGetValue(button, out var state); initialState[button] = (state ?? false) || buttonIsPressed; continue; } if (initialState[button] != null && initialState[button] != buttonIsPressed) { initialState[button] = null; } if (initialState[button] == null) { if (buttonIsPressed) { if (!TKButtonsHeld[button]) { OnTKButtonPress(button); } TKButtonsHeld[button] = true; inputPressed = true; } else { TKButtonsHeld[button] = false; } } } } } catch { TKButtonsInitialState[i] = null; } } if (!inputPressed && FieldSet) { InputComplete(); } inputPoll.Start(); }; inputPoll.AutoReset = false; inputPoll.Start(); Application.Current.Exit += (sender, args) => { DXJoystick?.Dispose(); DirectInput?.Dispose(); inputPoll.Close(); }; }
public void Destroy() { joystick.Unacquire(); joystick.Dispose(); directInput.Dispose(); }