public PadConfigWindow(CLROBS.XElement config) { InitializeComponent(); dInput = new SharpDX.DirectInput.DirectInput(); var list = dInput.GetDevices(SharpDX.DirectInput.DeviceType.Gamepad, SharpDX.DirectInput.DeviceEnumerationFlags.AttachedOnly); foreach (var item in list) { PadBox.Items.Add(new { item.ProductName }); } DebugText.Text = "not used curently - debug see OBS logs"; }
public InputManager(Game game, ActiveDevice device = ActiveDevice.Keyboard | ActiveDevice.Pad, int lever = 500) { Game = game; DirectInput = new SharpDX.DirectInput.DirectInput(); LeverDead = lever; MouseState = new MouseState(); var ms = MSInput::Mouse.GetState(); MouseState.X = ms.X; MouseState.Y = ms.Y; ControlState = new ControlState(); GamePlayControlState = new ControlState(); keyConfig = KeyboardConfig.GetDefault(); padConfig = PadConfig.GetDefault(); InitDevices(device); GetPushedKey();//������ }
public FizzyoInput() { directInput = new SharpDX.DirectInput.DirectInput(); //var devices = directInput.GetDevices(); var devices = directInput.GetDevices(SharpDX.DirectInput.DeviceType.Supplemental, SharpDX.DirectInput.DeviceEnumerationFlags.AllDevices); joysticks = new SharpDX.DirectInput.Joystick[devices.Count]; joysticksDeadzoneX = new int[devices.Count]; for (int i = 0; i < devices.Count; i++) { var joystickGuid = devices[i].InstanceGuid; joysticks[i] = new SharpDX.DirectInput.Joystick(directInput, joystickGuid); joysticks[i].Acquire(); var deadzone = joysticks[i].GetCurrentState(); joysticksDeadzoneX[i] = deadzone.X - 500; } }
/// <summary> /// 不间断尝试重新连接手柄 /// </summary> private void TJsGet() { int JoystickCount = 0; var dirInput = new SharpDX.DirectInput.DirectInput(); while (true) { if (JoystickName != "") { //已经接入最大数量的手柄了 //10s检测一次手柄掉线,如果未掉线,则跳过 Thread.Sleep(10000); continue; } var allDevices = dirInput.GetDevices(); foreach (var item in allDevices) { if (SharpDX.DirectInput.DeviceType.Joystick == item.Type) { //记录新建线程的手柄名称 if (JoystickName == item.ProductName) { //说明已经接入这个手柄了 } else { JoystickName = item.ProductName; curJoystick = new SharpDX.DirectInput.Joystick(dirInput, item.InstanceGuid); curJoystick.Properties.AxisMode = SharpDX.DirectInput.DeviceAxisMode.Absolute; curJoystick.Acquire(); JoystickCount++; Thread t1 = new Thread(TJsListening); t1.IsBackground = true; t1.Start(); } break; //curJoystick.Unacquire();//释放手柄 } } if (JoystickCount == 0) { MessageBox.Show("手柄数量 " + JoystickCount.ToString()); } } }
public override void Dispose() { lock (_sync) { if (_joystick != null) { _joystick.Dispose(); _joystick = null; } if (_directInput != null) { _directInput.Dispose(); _directInput = null; } } _form.Dispose(); _timer.Dispose(); }
public override bool Run() { lock (_sync) { try { if (_directInput == null) { _directInput = new SharpDX.DirectInput.DirectInput(); } if (_joystick == null) { var devices = _directInput.GetDevices(SharpDX.DirectInput.DeviceClass.GameControl, SharpDX.DirectInput.DeviceEnumerationFlags.AttachedOnly); if (devices.Count == 0) { ShowError("Джойстик не обнаружен!"); return(false); } _joystick = new SharpDX.DirectInput.Joystick(_directInput, devices[0].InstanceGuid); _joystick.SetCooperativeLevel(_form.Handle, SharpDX.DirectInput.CooperativeLevel.Background | SharpDX.DirectInput.CooperativeLevel.NonExclusive); _joystick.Properties.BufferSize = 128; } _joystick.Acquire(); _timer.Change(Period, Period); _acquired = true; return(true); } catch (Exception exc) { ShowError(exc.Message); return(false); } } }
private void SetInputs() { var directInput = new SharpDX.DirectInput.DirectInput(); this.Keyboard = new SharpDX.DirectInput.Keyboard(directInput); this.Keyboard.Properties.BufferSize = 128; this.Keyboard.Acquire(); this.Mouse = new Mouse(directInput); this.Mouse.Properties.AxisMode = SharpDX.DirectInput.DeviceAxisMode.Relative; this.Mouse.Properties.BufferSize = 128; this.Mouse.Acquire(); }
public void CreateDevice() { SharpDX.DirectInput.DirectInput dinput = new SharpDX.DirectInput.DirectInput(); SharpDX.DirectInput.CooperativeLevel cooperativeLevel; cooperativeLevel = SharpDX.DirectInput.CooperativeLevel.NonExclusive; cooperativeLevel |= SharpDX.DirectInput.CooperativeLevel.Background; mouse = new SharpDX.DirectInput.Mouse(dinput); mouse.SetCooperativeLevel(Window, cooperativeLevel); mouse.Acquire(); keyboard = new SharpDX.DirectInput.Keyboard(dinput); cooperativeLevel = SharpDX.DirectInput.CooperativeLevel.NonExclusive; cooperativeLevel |= SharpDX.DirectInput.CooperativeLevel.Foreground; keyboard.SetCooperativeLevel(Window, cooperativeLevel); keyboard.Acquire(); Point startPoint = System.Windows.Forms.Cursor.Position; mouseCoord.X = Window.PointToClient(startPoint).X; mouseCoord.Y = Window.PointToClient(startPoint).Y; mouseState = new SharpDX.DirectInput.MouseState(); keyboardState = new SharpDX.DirectInput.KeyboardState(); }
public void Refresh() { // Prevent this method from being spammed if (DateTime.Now.Subtract(_lastRefreshTime).TotalSeconds < 1) { return; } _lastRefreshTime = DateTime.Now; // Bluetooth Devices var devices = WinBtStream.GetPaths(); // Direct input Devices DInput = new SharpDX.DirectInput.DirectInput(); var joys = DInput.GetDevices(SharpDX.DirectInput.DeviceClass.GameControl, SharpDX.DirectInput.DeviceEnumerationFlags.AllDevices); foreach (var j in joys) { string pid = j.ProductGuid.ToString().Substring(0, 4); string vid = j.ProductGuid.ToString().Substring(4, 4); // devices to ignore if (vid == "057e" && (pid == "0330" || pid == "0306" || pid == "0337")) { continue; } else if (vid == "1234" && pid == "bead") { continue; } devices.Add(new Shared.DeviceInfo() { InstanceGUID = j.InstanceGuid, PID = pid, VID = vid }); } // GCN Adapter WinUsbStream gcnStream = new WinUsbStream(new UsbDeviceFinder(0x057E, 0x0337)); Shared.DeviceInfo gcnDevice = null; if (gcnStream.DeviceFound()) { gcnDevice = new Shared.DeviceInfo() { VID = "057E", PID = "0337", Type = NintrollerLib.ControllerType.Other }; devices.Add(gcnDevice); } #if DEBUG // Test GCN Device else { devices.Add(new Shared.DeviceInfo() { DevicePath = "Dummy GCN", PID = "0337", Type = NintrollerLib.ControllerType.Other }); } // Test Device devices.Add(new Shared.DeviceInfo() { DevicePath = "Dummy", Type = NintrollerLib.ControllerType.ProController }); devices.Add(new Shared.DeviceInfo() { DevicePath = "Dummy Wiimote", Type = NintrollerLib.ControllerType.Wiimote }); #endif foreach (var info in devices) { // Check if we are already showing this one DeviceStatus existing = _availableDevices.Find((d) => d.Info.SameDevice(info.DeviceID)); // If not add it if (existing == null) { var status = new DeviceStatus(info, info == gcnDevice ? gcnStream : null); status.ConnectClick = DoConnect; status.TypeUpdated = (s, t) => { var p = AppPrefs.Instance.GetDevicePreferences(s.Info.DevicePath); string title = ""; if (p != null && !string.IsNullOrWhiteSpace(p.nickname)) { title = p.nickname; } else { title = t.ToString(); } foreach (var tab in tabControl.Items) { if (tab is TabItem && (tab as TabItem).Content == s.Control) { ChangeIcon(tab as TabItem, t); ChangeTitle(tab as TabItem, title); } } }; status.CloseTab = (s) => { // Find associated tab, skip first as it is home for (int i = 1; i < tabControl.Items.Count; i++) { var tab = tabControl.Items[i]; if (tab is TabItem && (tab as TabItem).Content == s.Control) { tabControl.Items.RemoveAt(i); break; } } }; status.OnPrefsChange = (s, p) => { if (!string.IsNullOrWhiteSpace(p.nickname)) { foreach (var tab in tabControl.Items) { if (tab is TabItem && (tab as TabItem).Content == s.Control) { ChangeTitle(tab as TabItem, p.nickname); } } } }; status.OnRumbleSubscriptionChange = RumbleSettingsChanged; _availableDevices.Add(status); statusStack.Children.Add(status); DevicePrefs devicePrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID); if (devicePrefs.autoConnect) { status.AutoConnect(); } } else if (!existing.Connected) { DevicePrefs existingPrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID); if (existingPrefs.autoConnect) { existing.AutoConnect(); } } } }
private void loadJoy() { var Joystick1 = System.Configuration.ConfigurationManager.AppSettings["Joystick1"]; var Joystick2 = System.Configuration.ConfigurationManager.AppSettings["Joystick2"]; string joy1 = ""; if (Joystick1 != null) { joy1 = Joystick1.ToString(); } string joy2 = ""; if (Joystick2 != null) { joy2 = Joystick2.ToString(); } int JoystickCount = 0; var dirInput = new SharpDX.DirectInput.DirectInput(); if (curJoystick == null) { curJoystick = new SharpDX.DirectInput.Joystick[2]; curJoystick[0] = null; curJoystick[1] = null; } bool bNeadJoy = false; if (curJoystick[0] == null && joy1 != "") { bNeadJoy = true; } if (curJoystick[1] == null && joy2 != "") { bNeadJoy = true; } if (!bNeadJoy) { return; } var allDevices = dirInput.GetDevices(); foreach (var item in allDevices) { if (SharpDX.DirectInput.DeviceType.Joystick == item.Type) { //记录新建线程的手柄名称 if (item.ProductName == joy1) { curJoystick[0] = new SharpDX.DirectInput.Joystick(dirInput, item.InstanceGuid); curJoystick[0].Properties.AxisMode = SharpDX.DirectInput.DeviceAxisMode.Absolute; curJoystick[0].Acquire(); JoystickCount++; if (t1 != null) { t1.Abort(); } t1 = new Thread(TJsListening1); t1.IsBackground = true; t1.Start(); } else if (item.ProductName == joy2) { curJoystick[1] = new SharpDX.DirectInput.Joystick(dirInput, item.InstanceGuid); curJoystick[1].Properties.AxisMode = SharpDX.DirectInput.DeviceAxisMode.Absolute; curJoystick[1].Acquire(); JoystickCount++; if (t2 != null) { t2.Abort(); } t2 = new Thread(TJsListening2); t2.IsBackground = true; t2.Start(); } //curJoystick.Unacquire();//释放手柄 } } }
public void Dispose() { directInput = null; }
public void Refresh() { // Prevent this method from being spammed if (DateTime.Now.Subtract(_lastRefreshTime).TotalSeconds < 1) { return; } _lastRefreshTime = DateTime.Now; var devices = WinBtStream.GetPaths(); // Direct input Devices DInput = new SharpDX.DirectInput.DirectInput(); var joys = DInput.GetDevices(SharpDX.DirectInput.DeviceClass.GameControl, SharpDX.DirectInput.DeviceEnumerationFlags.AllDevices); foreach (var j in joys) { string pid = j.ProductGuid.ToString().Substring(0, 4); string vid = j.ProductGuid.ToString().Substring(4, 4); // devices to ignore if (vid == "057e" && (pid == "0330" || pid == "0306")) { continue; } else if (vid == "1234" && pid == "bead") { continue; } devices.Add(new Shared.DeviceInfo() { InstanceGUID = j.InstanceGuid, PID = pid, VID = vid }); } foreach (var info in devices) { // Check if we are already showing this one DeviceStatus existing = _availableDevices.Find((d) => d.Info.SameDevice(info.DeviceID)); // If not add it if (existing == null) { var status = new DeviceStatus(info); status.ConnectClick = DoConnect; status.TypeUpdated = (s, t) => { var p = AppPrefs.Instance.GetDevicePreferences(s.Info.DevicePath); string title = ""; if (p != null && !string.IsNullOrWhiteSpace(p.nickname)) { title = p.nickname; } else { title = t.ToString(); } foreach (var tab in tabControl.Items) { if (tab is TabItem && (tab as TabItem).Content == s.Control) { ChangeIcon(tab as TabItem, t); ChangeTitle(tab as TabItem, title); } } }; status.CloseTab = (s) => { // Find associated tab, skip first as it is home for (int i = 1; i < tabControl.Items.Count; i++) { var tab = tabControl.Items[i]; if (tab is TabItem && (tab as TabItem).Content == s.Control) { tabControl.Items.RemoveAt(i); break; } } }; status.OnPrefsChange = (s, p) => { if (!string.IsNullOrWhiteSpace(p.nickname)) { foreach (var tab in tabControl.Items) { if (tab is TabItem && (tab as TabItem).Content == s.Control) { ChangeTitle(tab as TabItem, p.nickname); } } } }; _availableDevices.Add(status); statusStack.Children.Add(status); DevicePrefs devicePrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID); if (devicePrefs.autoConnect) { status.AutoConnect(); } } else if (!existing.Connected) { DevicePrefs existingPrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID); if (existingPrefs.autoConnect) { existing.AutoConnect(); } } } }
public GamePad( IWindow window ) { dInput = new SharpDX.DirectInput.DirectInput (); Guid gamePadGuid = Guid.Empty; foreach ( var deviceInstance in dInput.GetDevices ( SharpDX.DirectInput.DeviceType.Gamepad, SharpDX.DirectInput.DeviceEnumerationFlags.AllDevices ) ) gamePadGuid = deviceInstance.InstanceGuid; if ( gamePadGuid != Guid.Empty ) { device = new SharpDX.DirectInput.Joystick ( dInput, gamePadGuid ); device.SetCooperativeLevel ( ( window.Handle as Form ).Handle, SharpDX.DirectInput.CooperativeLevel.Background | SharpDX.DirectInput.CooperativeLevel.NonExclusive ); device.Properties.BufferSize = 128; device.Acquire (); } }