public DirectInputKeyboard(DeviceInstance dev) { Acquired = false; DeviceInstance = dev; _pollTimer = new Timer(new TimerCallback(poll_Tick), null, Timeout.Infinite, Timeout.Infinite); OnAcquire += new EventHandler<EventArgs>(Keyboard_OnAcquire); }
public DirectInputJoystick( DeviceInstance dev, DeviceType type ) { DeviceInstance = dev; Type = type; Acquired = false; ExclusiveMode = false; _pollTimer = new Timer(new TimerCallback(poll_Tick), null, Timeout.Infinite, Timeout.Infinite); OnAcquire += new EventHandler<EventArgs>(Joystick_OnAcquire); }
private Joystick FindJoystick(List <Joystick> joysticks, DeviceInstance device) { foreach (Joystick joystick in joysticks) { if (joystick.Information.InstanceGuid == device.InstanceGuid) { return(joystick); } } return(null); }
// コンストラクタ public CInputJoystick(IntPtr hWnd, DeviceInstance di, DirectInput directInput) { this.e入力デバイス種別 = E入力デバイス種別.Joystick; this.GUID = di.InstanceGuid.ToString(); this.ID = 0; try { this.devJoystick = new Joystick(directInput, di.InstanceGuid); this.devJoystick.SetCooperativeLevel(hWnd, CooperativeLevel.Foreground | CooperativeLevel.Exclusive); this.devJoystick.Properties.BufferSize = 32; Trace.TraceInformation(this.devJoystick.Information.InstanceName + "を生成しました。"); this.strDeviceName = this.devJoystick.Information.InstanceName; } catch { if (this.devJoystick != null) { this.devJoystick.Dispose(); this.devJoystick = null; } Trace.TraceError(this.devJoystick.Information.InstanceName, new object[] { " の生成に失敗しました。" }); throw; } foreach (DeviceObjectInstance instance in this.devJoystick.GetObjects()) { if ((instance.ObjectId.Flags & DeviceObjectTypeFlags.Axis) != DeviceObjectTypeFlags.All) { this.devJoystick.GetObjectPropertiesById(instance.ObjectId).Range = new InputRange(-1000, 1000); this.devJoystick.GetObjectPropertiesById(instance.ObjectId).DeadZone = 5000; // 50%をデッドゾーンに設定 // 軸をON/OFFの2値で使うならこれで十分 } } try { this.devJoystick.Acquire(); } catch { } for (int i = 0; i < this.bButtonState.Length; i++) { this.bButtonState[i] = false; } for (int i = 0; i < this.nPovState.Length; i++) { this.nPovState[i] = -1; } //this.timer = new CTimer( CTimer.E種別.MultiMedia ); this.list入力イベント = new List <STInputEvent>(32); }
public static NodeDevice StaticBuild(DirectInput directInput, DeviceInstance deviceInstance) { NodeDevice result; using (var joystick = new Joystick(directInput, deviceInstance.InstanceGuid)) { var capabilities = joystick.Capabilities; result = StaticBuildHelper(deviceInstance.InstanceName, TYPE_ID, deviceInstance.InstanceGuid, CODE, capabilities.ButtonCount, capabilities.AxesCount, capabilities.PovCount); } return result; }
public KeyboardInterface(Form form) { if (keyboardList.Count > 0) { keyboardList.MoveNext(); DeviceInstance deviceInstance = (DeviceInstance)keyboardList.Current; keyboard = new Device(deviceInstance.InstanceGuid); keyboard.SetCooperativeLevel(form, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive); } keyboard.SetDataFormat(DeviceDataFormat.Keyboard); keyboard.Acquire(); }
public void LoadData(DeviceInstance di, int padIndex) { _di = di; _padIndex = padIndex; Text = string.Format(Text, di.ProductName); Step1TabPage.Text = string.Format("{0} - {1:N}", di.ProductName, di.InstanceGuid); Step2TabPage.Text = string.Format("{0} - {1:N}", di.ProductName, di.InstanceGuid); DescriptionLabel.Text = string.Format(DescriptionLabel.Text, di.ProductName, di.InstanceGuid.ToString("N")); BackButton.Visible = false; ResultsLabel.Text = ""; UpdateButtons(); }
/// <summary> /// Creates an instance of DInputHandler object for a FFB device and adds it to diHandlers dictionary under /// "devIdx" index. /// </summary> /// <param name="ffbDev"> /// DeviceInstance returned by DirectInput::GetDevices. /// </param> /// <param name="devIdx"> /// Index of the device in the enumeration of FFB devices. /// </param> private void HandleFFBDevice(DeviceInstance ffbDev, int devIdx) { DInputHandler dih = new DInputHandler(ffbDev.InstanceGuid); if (!dih.InitDevice(this.Handle)) { return; } diHandlers.Add(devIdx, dih); cboxDevices.Items.Add(ffbDev.ProductName + " (" + ffbDev.InstanceGuid.ToString() + ")"); }
static void PrintControllerInfo() { Console.WriteLine("\nSearching for DirectInput Devices...\n"); DirectInput dinput = new DirectInput(); IList <DeviceInstance> devices = dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly); for (int i = 0; i < devices.Count; i++) { DeviceInstance device = devices[i]; Console.WriteLine("Device #" + i + " Found: " + device.ProductName); } Console.WriteLine("Done.\n"); }
public void connectGamepad() { gamepadDevice = null; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { gamepadDevice = deviceInstance; Console.WriteLine(deviceInstance.InstanceName); } Thread thread = new Thread(readInput); thread.Start(); }
private void CheckOneDevice(DeviceInstance di) { int index = m_joysticks.Count; if (index == 2) { return; } Joystick j = new Joystick(m_di, di.InstanceGuid); j.Acquire(); m_joysticks[index] = j; }
/// <summary> /// Opens a new game controller or gamepad /// </summary> /// <param name="deviceInstance">The device instance</param> public void OpenDevice(DeviceInstance deviceInstance) { // Ignore XInput devices since they are handled by XInput if (XInputChecker.IsXInputDevice(ref deviceInstance.ProductGuid)) { return; } if (Devices.ContainsKey(deviceInstance.InstanceGuid)) { throw new InvalidOperationException($"DirectInput GameController already opened {deviceInstance.InstanceGuid}/{deviceInstance.InstanceName}"); } GameControllerDirectInput controller; try { controller = new GameControllerDirectInput(this, directInput, deviceInstance); } catch (SharpDXException) { // Some failure occured during device creation return; } // Find gamepad layout var layout = GamePadLayouts.FindLayout(this, controller); if (layout != null) { // Creata a gamepad wrapping around the controller var gamePad = new GamePadDirectInput(this, inputManager, controller, layout); controller.Disconnected += (sender, args) => { // Queue device for removal devicesToRemove.Add(gamePad.Id); }; RegisterDevice(gamePad); // Register gamepad instead } else { controller.Disconnected += (sender, args) => { // Queue device for removal devicesToRemove.Add(controller.Id); }; RegisterDevice(controller); } }
internal DIDeviceInfo(DeviceInstance deviceInstance, GamingDeviceType gamingDeviceType) { DeviceSubType = deviceInstance.DeviceSubType; DeviceType = deviceInstance.DeviceType; FFDriverGuid = deviceInstance.FFDriverGuid; InstanceGuid = deviceInstance.InstanceGuid; InstanceName = deviceInstance.InstanceName; ProductGuid = deviceInstance.ProductGuid; ProductName = deviceInstance.ProductName; Usage = deviceInstance.Usage; UsagePage = deviceInstance.UsagePage; GamingDeviceType = gamingDeviceType; }
private IInputDevice CreateDevice(DeviceInstance deviceInstance, List <string> uniqueIds) { try { if (!directInput.IsDeviceAttached(deviceInstance.InstanceGuid)) { return(null); } var joystick = new Joystick(directInput, deviceInstance.InstanceGuid); if (joystick.Capabilities.AxeCount < 1 && joystick.Capabilities.ButtonCount < 1) { joystick.Dispose(); return(null); } bool isHid = deviceInstance.IsHumanInterfaceDevice; string interfacePath = null; string uniqueId; string hardwareId = null; if (isHid) { if (ignoredDeviceService.IsIgnored(joystick.Properties.InterfacePath)) { joystick.Dispose(); return(null); } interfacePath = joystick.Properties.InterfacePath; uniqueId = IdHelper.GetUniqueId(interfacePath); hardwareId = IdHelper.GetHardwareId(interfacePath); } else { uniqueId = IdHelper.GetUniqueId(deviceInstance.ProductGuid.ToString(), deviceInstance.InstanceGuid.ToString()); } uniqueIds.Add(uniqueId); if (currentDevices.Any(d => d.UniqueId == uniqueId)) { joystick.Dispose(); return(null); } joystick.Properties.BufferSize = 128; return(new DirectInputDevice(joystick, deviceInstance.InstanceGuid.ToString(), deviceInstance.ProductName, deviceInstance.ForceFeedbackDriverGuid != Guid.Empty, uniqueId, hardwareId, interfacePath)); } catch (Exception ex) { logger.Error("Failed to create device " + deviceInstance.InstanceGuid + " " + deviceInstance.InstanceName + ex.ToString()); return(null); } }
/// <summary> /// Get array[4] of direct input devices. /// </summary> DeviceInstance[] GetDevices() { var devices = Manager.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices).ToList(); // Move gaming wheels to the top index position by default. // Games like GTA need wheel to be first device to work properly. var wheels = devices.Where(x => x.Type == SharpDX.DirectInput.DeviceType.Driving || x.Subtype == (int)DeviceSubType.Wheel).ToArray(); foreach (var wheel in wheels) { devices.Remove(wheel); devices.Insert(0, wheel); } var orderedDevices = new DeviceInstance[4]; // Assign devices to their positions. for (int d = 0; d < devices.Count; d++) { var ig = devices[d].InstanceGuid; var section = SettingManager.Current.GetInstanceSection(ig); var ini2 = new Ini(SettingManager.IniFileName); string v = ini2.GetValue(section, SettingName.MapToPad); int mapToPad = 0; if (int.TryParse(v, out mapToPad) && mapToPad > 0 && mapToPad <= 4) { // If position is not occupied then... if (orderedDevices[mapToPad - 1] == null) { orderedDevices[mapToPad - 1] = devices[d]; } } } // Get list of unassigned devices. var unassignedDevices = devices.Except(orderedDevices).ToArray(); for (int i = 0; i < unassignedDevices.Length; i++) { // Assign to first empty slot. for (int d = 0; d < orderedDevices.Length; d++) { // If position is not occupied then... if (orderedDevices[d] == null) { orderedDevices[d] = unassignedDevices[i]; break; } } } return(orderedDevices); }
private static void InternalRenderGray2Device(DeviceInstance device, ushort width, ushort height, IntPtr currbuffer) { var frameSize = width * height; var frame = new byte[frameSize]; Marshal.Copy(currbuffer, frame, 0, frameSize); if (width == 128 && height == 16) { device.DmdDevice.RenderGray2(device.DmdFrame.Update(width, height, frame)); } else { device.DmdDevice.RenderGray2(device.DmdFrame.Update(width > aniWidth ? width : aniWidth, height > aniHeight ? height : aniHeight, frame)); } }
public void FindDevices() { Joysticks = new Dictionary <Guid, string>(); DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly); if (gameControllerList.Count > 0) //is there at least one device { for (Int32 i = 1; i <= gameControllerList.Count; i++) //run trough devices { gameControllerList.MoveNext(); //choose next device DeviceInstance deviceInstance = (DeviceInstance)gameControllerList.Current; //create deviceinstance Joysticks.Add(deviceInstance.ProductGuid, deviceInstance.ProductName); } } }
public InputDeviceMouse(DirectInput di, DeviceInstance d) { // those silly foreign people call mouse something other than it in english, so we need to fix it to english msi = new InputDeviceIdentity() { Instanceguid = d.InstanceGuid, Productguid = d.ProductGuid, Name = "Mouse" }; mouse = new SharpDX.DirectInput.Mouse(di); mouse.SetNotification(eventhandle); mouse.Acquire(); Capabilities c = mouse.Capabilities; butstate = new bool[c.ButtonCount]; }
private Joystick Acquire(DeviceInstance di) { DirectInput dinput = new DirectInput(); var pad = new Joystick(dinput, di.InstanceGuid); foreach (DeviceObjectInstance doi in pad.GetObjects(ObjectDeviceType.Axis)) { //pad.GetObjectPropertiesById((int)doi.ObjectType).SetRange(-5000, 5000); } pad.Properties.AxisMode = DeviceAxisMode.Absolute; //pad.SetCooperativeLevel(parent, (CooperativeLevel.Nonexclusive | CooperativeLevel.Background)); pad.Acquire(); return(pad); }
/// <summary> /// Initializes a new instance of the <see cref="InputDeviceImp"/> class. /// </summary> /// <param name="instance">The DeviceInstance.</param> public InputDeviceImp(DeviceInstance instance) { _controller = instance; _deadZone = 0.1f; buttonsPressed = new bool[100]; _joystick = new Joystick(new DirectInput(), _controller.InstanceGuid); foreach (DeviceObjectInstance deviceObject in _joystick.GetObjects()) { if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0) _joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000); } _joystick.Acquire(); }
public DirectInputMouse(DeviceInstance dev) { Acquired = false; DeviceInstance = dev; CurrentValue = new Dictionary<MouseOffset, int>(); Sensitivity = new Dictionary<MouseOffset, int>(); foreach (var moff in DIUtils.AllNamesMouse) { CurrentValue.Add(moff.Key, 0); if (moff.Key < MouseOffset.Button0) Sensitivity.Add(moff.Key, DEFAULT_SENS); } _pollTimer = new Timer(new TimerCallback(poll_Tick), null, Timeout.Infinite, Timeout.Infinite); OnAcquire += new EventHandler<EventArgs>(Mouse_OnAcquire); }
private static void InternalRenderRaw2Device(DeviceInstance device, ushort width, ushort height, IntPtr currbuffer, ushort noOfRawFrames, IntPtr currrawbuffer) { var frameSize = width * height; var frame = new byte[frameSize]; Marshal.Copy(currbuffer, frame, 0, frameSize); var rawplanes = new byte[noOfRawFrames][]; var planeSize = frameSize / 8; for (int i = 0; i < noOfRawFrames; i++) { rawplanes[i] = new byte[planeSize]; Marshal.Copy(new IntPtr(currrawbuffer.ToInt64() + (i * planeSize)), rawplanes[i], 0, planeSize); } device.DmdDevice.RenderGray2(device.RawDmdFrame.Update(aniWidth, aniHeight, frame, rawplanes)); }
public DeviceInstance getCurrentDeviceInstance() { DeviceInstance curDevice = null; IList <DeviceInstance> ControllerList = directInput.GetDevices(); foreach (DeviceInstance di in ControllerList) { if (di.InstanceGuid == this.DeviceGuid) { curDevice = di; break; } } return(curDevice); }
private void listen(DeviceInstance controller) { var directInput = new DirectInput(); joystick = new Joystick(directInput, controller.InstanceGuid); joystick.Properties.BufferSize = 128; joystick.Acquire(); while (true) { joystick.Poll(); var datas = joystick.GetBufferedData(); foreach (var state in datas) { updateStatus(state.Offset.ToString(), state.Value); } } }
void RefreshDevice(UserDevice ud, DeviceInstance instance) { if (Program.IsClosing) { return; } ud.LoadInstance(instance); var device = new Joystick(Manager, instance.InstanceGuid); ud.Device = device; ud.LoadCapabilities(device.Capabilities); // If device is set as offline then make it online. if (!ud.IsOnline) { ud.IsOnline = true; } }
private void timer1_Tick(object sender, EventArgs e) { if (button2.BackColor != Color.Green) { button2.BackColor = Color.Green; } else { button2.BackColor = Color.Blue; } button2.Update(); if (button1.BackColor != Color.Green) { timer1.Enabled = false; button1.BackColor = Color.Red; pad = null; device = null; comboBox1.Text = ""; comboBox1.SelectedIndex = -1; return; } try { pad.Poll(); JoystickState state = pad.GetCurrentState(); if (lastState == null) { lastState = state; updateDraw(); return; } string A = string.Join("|", state.Buttons); string B = string.Join("|", lastState.Buttons); if (A != B) { lastState = state; updateDraw(); } } catch (Exception ex) { textBox2.Text = ex.Message; button1.BackColor = Color.Yellow; } }
bool DetectDevice(DeviceInstance deviceInstance, ref Joystick dev, string name, ref Guid preferGuid, Action <Guid> feedback) { if (deviceInstance.ProductName.StartsWith(name, StringComparison.OrdinalIgnoreCase) && (preferGuid == Guid.Empty || deviceInstance.InstanceGuid == preferGuid)) { preferGuid = deviceInstance.InstanceGuid; // create a device from this controller. dev = new Joystick(input, deviceInstance.InstanceGuid); dev.SetCooperativeLevel(mainForm.Handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); // Tell DirectX that this is a Joystick. //dev.SetDataFormat(DeviceDataFormat.Joystick); // Finally, acquire the device. dev.Acquire(); feedback(deviceInstance.InstanceGuid); return(true); } return(false); }
/// <summary> /// Determines whether the specified DirectInput device is handled by XINPUT /// </summary> /// <param name="deviceInstance"> /// The DirectInput device instance that will be checked /// </param> /// <returns>True if this is a device that is handled by XINPUT</returns> /// <remarks> /// <para> /// XINPUT devices are accessable through both DirectInput and XINPUT. /// Since we're already using XINPUT (through XNA), we need to filter out /// any DirectInput devices that we already access through XINPUT, otherwise, /// each XINPUT game controller would appear twice. /// </para> /// <para> /// This method is based on the code from the ZMan's article on detecting /// which DirectInput devices are also XInput devices: /// http://www.thezbuffer.com/articles/351.aspx /// </para> /// </remarks> private static bool isXInputDevice(DeviceInstance deviceInstance) { // For XINPUT controllers, the first 8 characters of the device GUID // contain the VID and PID of the USB device string productGuid = deviceInstance.ProductGuid.ToString(); int searchedVid = Convert.ToInt32(productGuid.Substring(4, 4), 16); int searchedPid = Convert.ToInt32(productGuid.Substring(0, 4), 16); // Query WMI for any plug and play devices with IG_ in their device name, // this identifies XInput devices var searcher = new ManagementObjectSearcher( "select DeviceID from Win32_PNPEntity where DeviceID like '%IG[_]%' " ); // Look for the queried game pad's VID and PID appear the list of // XInput devices foreach (ManagementObject managementObject in searcher.Get()) { object usbId = managementObject["DeviceID"]; if (usbId == null) { continue; } int vid, pid; if (!tryExtractVidPid(usbId.ToString(), out vid, out pid)) { continue; } // If the the queried game pad's VID and PID match, it was in the list // of XInput devices, ergo it is an XInput device if ((vid == searchedVid) && (pid == searchedPid)) { return true; } } // Not found, game pad is not an XInput device return false; }
public bool Same(DeviceInstance other) { return other != null && (Id == GuidToString(other.ProductGuid) || DisplayName == other.InstanceName); }
public static DirectInputDevice Create(SlimDX.DirectInput.DirectInput directInput, DeviceInstance device, int iniId) { try { return new DirectInputDevice(directInput, device, iniId); } catch (DirectInputException) { return null; } }
private static IEnumerable<string> IterateTopology(DeviceInstance dev) { if (dev == null || dev.Line == null) yield break; yield return dev.Line.Name; yield return dev.Line.Description; if (dev.Line.Area == null) yield break; yield return dev.Line.Area.Name; yield return dev.Line.Area.Description; if (dev.Line.Area.Installation == null) yield break; yield return dev.Line.Area.Installation.Name; }
/// <summary> /// Creates an instance of DInputHandler object for a FFB device and adds it to diHandlers dictionary under /// "devIdx" index. /// </summary> /// <param name="ffbDev"> /// DeviceInstance returned by DirectInput::GetDevices. /// </param> /// <param name="devIdx"> /// Index of the device in the enumeration of FFB devices. /// </param> private void HandleFFBDevice(DeviceInstance ffbDev, int devIdx) { DInputHandler dih = new DInputHandler(ffbDev.InstanceGuid); if (!dih.InitDevice(this.Handle, cbAutoCentering.Checked)) return; diHandlers.Add(devIdx, dih); cboxDevices.Items.Add(ffbDev.ProductName + " (" + ffbDev.InstanceGuid.ToString() + ")"); }
public xJoypad(DeviceInstance d) { dix = d; }