private void Form1_Load(object sender, EventArgs e) { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Keyboard, DeviceEnumerationFlags.AllDevices)) { controllers.Add(deviceInstance.InstanceGuid); comboBox1.Items.Add(deviceInstance.ProductName); } //controllers.Add(directInput.GetDevices(DeviceType.Keyboard, DeviceEnumerationFlags.AllDevices)); foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { controllers.Add(deviceInstance.InstanceGuid); comboBox1.Items.Add(deviceInstance.ProductName); } // If Joystick not found, throws an error if (controllers.Count < 1) { if (MessageBox.Show("No Joystick or Keyboard has been found please try again\nProgram now will exit !", "No Controller Found", MessageBoxButtons.OK) == DialogResult.OK) Application.Exit(); } }
private static void StartJoystickCapture(CancellationToken token) { var joystickGuid = Guid.Empty; var di = new DirectInput(); foreach (var device in di.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly)) { joystickGuid = device.InstanceGuid; break; } _joystick = new SharpDX.DirectInput.Joystick(di, joystickGuid); _joystick.Acquire(); _currentThrottle = 0; _currentYawTrim = 0; while (!token.IsCancellationRequested) { var state = _joystick.GetCurrentState(); _currentThrottle = (1000 - GetAnalogStickValue(state.Sliders[0])) / 2; Helicopter.Command.MainThrottle = _currentThrottle; Helicopter.Command.Pitch = GetAnalogStickValue(state.Y); //Helicopter.Command.Yaw = -1 * (GetAnalogStickValue(state.X) + _currentYawTrim); //For n64 controller Helicopter.Command.Yaw = -1 * (GetAnalogStickValue(state.RotationZ) + _currentYawTrim); var yawtrimChange = GetYawTrimChange(state.Buttons); _currentYawTrim += yawtrimChange; Helicopter.Command.YawTrim = _currentYawTrim; SetConsoleDisplay(state); Thread.Sleep(Speed); } }
/// <summary> /// 番号指定でデバイス生成。番号のデバイスが存在しなければ例外を投げる。 /// </summary> /// <param name="window"></param> /// <param name="padNumber">0始まり</param> public GamePadDevice(int padNumber, DirectInput directInput) { var devices = GetDevices(directInput); if (devices.Count <= padNumber) { throw new Exception("指定された数のパッドがつながれていない"); } try { Stick = new Joystick(directInput, devices[padNumber].InstanceGuid); //Stick.SetCooperativeLevel(window, CooperativeLevel.Exclusive | CooperativeLevel.Foreground); } catch (Exception e) { throw new Exception("パッドの初期化に失敗", e); } ///スティックの範囲設定 foreach (var item in Stick.GetObjects()) { //if ((item.ObjectType & .Axis) != 0) //{ // Stick.GetObjectPropertiesById((int)item.ObjectType).SetRange(-1000, 1000); //} } Stick.Acquire(); }
public override void Dispose() { if (mouse != null) mouse.Unacquire(); mouse = null; directInput = null; }
public DirectInputGamePad(DirectInput directInput, GamePadKey key) : base(key) { this.key = key; this.directInput = directInput; this.instance = new Joystick(directInput, key.Guid); joystickState = new JoystickState(); }
//Disable all dinput devices for xinput controllers public void Lock_DX_Devices() { var directInput = new DirectInput(); try { IList<DeviceInstance> devicelist = directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly); foreach (DeviceInstance cdevice in devicelist) { if (cdevice.InstanceName.Trim('\0') == XINPUT_NAME) { var joystick = new Joystick(directInput, cdevice.InstanceGuid); joystick.Acquire(); Guid deviceGUID = joystick.Properties.ClassGuid; string devicePath = joystick.Properties.InterfacePath; joystick.Unacquire(); string[] dpstlit = devicePath.Split('#'); devicePath = @"HID\" + dpstlit[1].ToUpper() + @"\" + dpstlit[2].ToUpper(); lockedDevices.Add(new DeviceID(deviceGUID, devicePath)); DeviceHelper.SetDeviceEnabled(deviceGUID, devicePath, false); } } } finally { directInput.Dispose(); } }
public GamePad(DirectInput directInput, DeviceInstance deviceInstance) { this.directInput = directInput; this.device = new Joystick(directInput, deviceInstance.InstanceGuid); this.device.Acquire(); UpdateState(); }
private void ConfigEditDialog_Load(object sender, EventArgs e) { directInput = new DirectInput(); var list = directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly); if (list.Count > 0) { inputDevice = new Joystick(directInput, list.First().InstanceGuid); tableLayoutPanel1.RowCount = actionNames.Length; for (int i = 0; i < actionNames.Length; i++) { tableLayoutPanel1.Controls.Add(new Label() { AutoSize = true, Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top, Text = actionNames[i], TextAlign = ContentAlignment.MiddleLeft }, 0, i); ButtonControl buttonControl = new ButtonControl() { Enabled = false }; tableLayoutPanel1.Controls.Add(buttonControl, 1, i); buttonControls.Add(buttonControl); buttonControl.SetButtonClicked += buttonControl_SetButtonClicked; buttonControl.ClearButtonClicked += buttonControl_ClearButtonClicked; if (i == tableLayoutPanel1.RowStyles.Count) tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize)); } } else tabControl1.TabPages.Remove(tabPage_Controller); // Load the config INI upon window load LoadConfigIni(); }
/// <summary>Creates a new SharpDXInputSystem.</summary> /// <param name="control">The control to associate with DirectInput.</param> public SharpDXInputSystem(WF.Control control) { _directInput = new DI.DirectInput(); InitialiseKeyboard(control); InitialiseJoystick(); }
private void CreateNativeKeyboard() { nativeState = new DInput.KeyboardState(); directInput = new DInput.DirectInput(); nativeKeyboard = new DInput.Keyboard(directInput); nativeKeyboard.SetCooperativeLevel(windowHandle, DInput.CooperativeLevel.NonExclusive | DInput.CooperativeLevel.Background); nativeKeyboard.Acquire(); }
private static void RunManager(InputConfig config) { try { var input = new DirectInput(); var devices = new List<DeviceInstance>(input.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)); devices.AddRange(input.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)); var registeredDevices = new List<Tuple<Config.Input, Joystick>>(); foreach (var inp in config.Inputs) { var device = devices.SingleOrDefault(di => di.ProductGuid == new Guid(inp.Guid)); if (device == null) { throw new Exception($"Device \"{inp.Nickname}\" not found"); } var joy = new Joystick(input, device.InstanceGuid); registeredDevices.Add(Tuple.Create(inp, joy)); } while (true) { var frame = new InputFrame(); frame.GenerationTime = DateTime.Now; foreach (var registeredDevice in registeredDevices) { var state = registeredDevice.Item2.GetCurrentState(); switch (registeredDevice.Item1.Type.ToUpper()) { case "JOYSTICK": frame.SubFrames.Add(new JoystickSubFrame(state)); break; case "GAMEPAD": frame.SubFrames.Add(new GamepadSubFrame(state)); break; } } FrameCaptured?.Invoke(frame); } } catch (ThreadAbortException) { Console.Error.WriteLine("Input Manager Stopped at " + DateTime.Now.ToString("G")); } catch (Exception ex) { MessageBox.Show($"Error: {ex.Message}\n\nInput Manager cannot continue", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static void HandleJoystick() { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) joystickGuid = deviceInstance.InstanceGuid; // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) joystickGuid = deviceInstance.InstanceGuid; // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { Debug.WriteLine("No Gamepad found."); Environment.Exit(1); } // Instantiate the joystick var joystick = new Joystick(directInput, joystickGuid); Debug.WriteLine("Found Gamepad with GUID: {0}", joystickGuid); // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); // Poll events from joystick every 1 millisecond var timer = Observable.Interval(TimeSpan.FromMilliseconds(1)); timer // Get all joystick input .SelectMany(_ => { joystick.Poll(); return joystick.GetBufferedData(); }) // Filter only menu key button (xbox one controller) .Where(a => a.Offset == JoystickOffset.Buttons6) // Input will contain UP and Down button events .Buffer(2) // If button was pressed longer than a second .Where(t => (TimeSpan.FromMilliseconds(t.Last().Timestamp) - TimeSpan.FromMilliseconds(t.First().Timestamp)).TotalSeconds >= 1) // Press and hold F key for 1.5s .Subscribe(t => { SendKeyDown(KeyCode.KEY_F); System.Threading.Thread.Sleep(1500); SendKeyUp(KeyCode.KEY_F); }); }
/// <summary> /// Initializes a new instance of the <see cref="DirectInputDevice"/> class. /// </summary> /// <param name="deviceInfo">The gaming device information for the specific device to use.</param> /// <param name="directInput">The direct input interface to use when creating the object.</param> public DirectInputDevice(DirectInputDeviceInfo deviceInfo, DI.DirectInput directInput) : base(deviceInfo) { _directInput = directInput; _info = deviceInfo; _joystick = new Lazy <DI.Joystick>(() => CreateJoystick(directInput, deviceInfo), true); }
public Gamepad() { dInput = new DI.DirectInput(); var list = dInput.GetDevices(DI.DeviceType.Gamepad, DI.DeviceEnumerationFlags.AttachedOnly); if (list.Count == 0) { list = dInput.GetDevices(DI.DeviceType.Joystick, DI.DeviceEnumerationFlags.AttachedOnly); if (list.Count == 0) { padConnected = false; } else { padConnected = true; } } else { padConnected = true; } if (padConnected) { padTrans = new bool[8]; Pad = new DI.Joystick(dInput, list[0].InstanceGuid); //Pad.Acquire(); } }
static void Main(string[] args) { // Initialize DirectInput var dirInput = new SharpDX.DirectInput.DirectInput(); var typeJoystick = SharpDX.DirectInput.DeviceType.Gamepad; var allDevices = dirInput.GetDevices(); bool isGetJoystick = false; foreach (var item in allDevices) { if (typeJoystick == item.Type) { curJoystick = new SharpDX.DirectInput.Joystick(dirInput, item.InstanceGuid); curJoystick.Acquire(); isGetJoystick = true; Thread t1 = new Thread(joyListening); t1.IsBackground = true; t1.Start(); } } if (!isGetJoystick) { Console.WriteLine("没有插入手柄"); Console.WriteLine("Press any key to exit!"); } Console.ReadKey(); }
/// <inheritdoc/> public IEnumerable <ILowLevelInputDevice> GetAllDevices() { var directInput = new SharpDX.DirectInput.DirectInput(); var devices = directInput.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly); var directInputGamepads = this.GetGenericGamepads(devices.Where(device => device.Type == SharpDX.DirectInput.DeviceType.Gamepad || device.Type == SharpDX.DirectInput.DeviceType .Joystick), directInput); var xinputGamepads = this.GetXInputGamepads(); var keyboards = directInput.GetDevices(DeviceClass.Keyboard, DeviceEnumerationFlags.AllDevices) .Select(keyboard => new LowLevelInputDevice() { DiscoveryApi = InputApi.DirectInput, DI_InstanceGUID = keyboard.InstanceGuid, DI_InstanceName = keyboard.InstanceName.Trim('\0'), DI_ProductName = keyboard.ProductName.Trim('\0'), DI_ProductGUID = keyboard.ProductGuid, DI_DeviceType = DeviceType.Keyboard, }); var mice = directInput.GetDevices(DeviceClass.Pointer, DeviceEnumerationFlags.AllDevices).Select(mouse => new LowLevelInputDevice() { DiscoveryApi = InputApi.DirectInput, DI_InstanceGUID = mouse.InstanceGuid, DI_InstanceName = mouse.InstanceName.Trim('\0'), DI_ProductName = mouse.ProductName.Trim('\0'), DI_ProductGUID = mouse.ProductGuid, DI_DeviceType = DeviceType.Mouse, }); return(directInputGamepads.Concat(xinputGamepads).Concat(keyboards).Concat(mice)); }
public void ObtainJoystick() { if (DJoystick != null) { DJoystick.Dispose(); } directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { joystickGuid = deviceInstance.InstanceGuid; } if (joystickGuid == Guid.Empty) { Log.LogMessage("No joystick connected"); return; } // Instantiate the joystick DJoystick = new DirectJoystick(directInput, joystickGuid); Log.LogMessage("Found Joystick with GUID: {0} Name: {1}", joystickGuid, DJoystick.Information.ProductName); // Set BufferSize in order to use buffered data. DJoystick.Properties.BufferSize = 128; // Acquire the joystick DJoystick.Acquire(); }
protected override void Dispose(bool disposeManagedResources) { if (!IsDisposed) { if (disposeManagedResources) { // Dispose managed resources. } // There are no unmanaged resources to release, but // if we add them, they need to be released here. if (this._joystick != null) { try { this._joystick.Unacquire(); } finally { this._joystick.Dispose(); this._joystick = null; this._directInput = null; this._forceFeedback = null; } ((DirectXInputManager)Creator).ReleaseDevice <Joystick>(this._joyInfo); } } IsDisposed = true; // If it is available, make the call to the // base class's Dispose(Boolean) method base.Dispose(disposeManagedResources); }
public Game() { renderForm = new RenderForm("D3D11 Planets"); renderForm.MouseMove += (object sender, System.Windows.Forms.MouseEventArgs e) => { realMousePos = new Vector2(e.Location.X, e.Location.Y); }; renderForm.WindowState = System.Windows.Forms.FormWindowState.Maximized; renderForm.AllowUserResizing = true; renderForm.ClientSizeChanged += (object sender, EventArgs e) => { resizePending = true; }; DInput.DirectInput directInput = new DInput.DirectInput(); keyboard = new DInput.Keyboard(directInput); mouse = new DInput.Mouse(directInput); keyboard.Acquire(); mouse.Acquire(); renderer = new Renderer(this, renderForm); Shaders.Load(renderer.Device, renderer.Context); Resources.Load(renderer.Device); Initialize(); }
protected override void Initialize() { base.Initialize(); di = new SharpDX.DirectInput.DirectInput(); _subsysKeyboard = new Subsystem_Input_Keyboard(di); _subsysMouse = new Subsystem_Input_Mouse(di); }
/// <summary> /// Constructor for this class, defines the individual controller. /// </summary> public DInputController(SharpDX.DirectInput.DirectInput directInput, Guid deviceGuid) : base(directInput, deviceGuid) { // Instantiate the remapper. Remapper = new Remapper(Remapper.InputDeviceType.DirectInput, this); // Get the controller key binding. Remapper.GetMappings(); }
public override void Dispose() { if (mouse != null) { mouse.Unacquire(); } mouse = null; directInput = null; }
public GameCore() { _renderEngine = new RenderEngine(); _input = new DirectInput(); _keyboard = new Keyboard(_input); _mouse = new Mouse(_input); Initialize(); }
public SharpDXMouse(CursorPositionTranslater positionTranslater) { this.positionTranslater = positionTranslater; mouseCounter = new MouseDeviceCounter(); directInput = new DInput.DirectInput(); mouse = new DInput.Mouse(directInput); mouse.Properties.AxisMode = DInput.DeviceAxisMode.Absolute; mouse.Acquire(); currentState = new DInput.MouseState(); }
public override void Dispose() { if (nativeKeyboard != null) { nativeKeyboard.Unacquire(); nativeKeyboard = null; } directInput = null; }
public SharpDXMouse(Window window) { positionTranslater = new CursorPositionTranslater(window); mouseCounter = new MouseDeviceCounter(); directInput = new DInput.DirectInput(); mouse = new DInput.Mouse(directInput); mouse.Properties.AxisMode = DInput.DeviceAxisMode.Absolute; mouse.Acquire(); currentState = new DInput.MouseState(); }
private void CreateNativeKeyboard() { nativeState = new DInput.KeyboardState(); directInput = new DInput.DirectInput(); nativeKeyboard = new DInput.Keyboard(directInput); if (window.IsWindowsFormAndNotJustAPanel) nativeKeyboard.SetCooperativeLevel(window.Handle, DInput.CooperativeLevel.NonExclusive | DInput.CooperativeLevel.Background); nativeKeyboard.Acquire(); }
public override void Dispose() { if (nativeKeyboard != null) { nativeKeyboard.Unacquire(); nativeKeyboard = null; } directInput = null; IsAvailable = false; }
public GamePad() { // Initialize DirectInput directInput = new DirectInput(); // Find a Joystick Guid joystickGuid = Guid.Empty; // Find a Gamepad foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) joystickGuid = deviceInstance.InstanceGuid; // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) joystickGuid = deviceInstance.InstanceGuid; // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { Logger.Log(this, "No joystick/Gamepad found.", 2); } else { // Instantiate the joystick joystick = new Joystick(directInput, joystickGuid); Logger.Log(this, String.Format("Found Joystick/Gamepad with GUID: {0}", joystickGuid), 1); // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); // Poll events from joystick //while (true) //{ // joystick.Poll(); // var datas = joystick.GetBufferedData(); // foreach (var state in datas) // Console.WriteLine(state); //} timer = new Timer(); timer.Interval = TIMER_INTERVAL_IN_MS; timer.Tick += new EventHandler(timer_Tick); timer.Start(); } }
private void CreateNativeKeyboard() { nativeState = new DInput.KeyboardState(); directInput = new DInput.DirectInput(); nativeKeyboard = new DInput.Keyboard(directInput); if (window.IsWindowsFormAndNotJustAPanel) { nativeKeyboard.SetCooperativeLevel(window.Handle, DInput.CooperativeLevel.NonExclusive | DInput.CooperativeLevel.Background); } nativeKeyboard.Acquire(); }
public GamePad(int lever, int padNumber, DirectInput directInput) { Config = PadConfig.GetDefault(); StickBorder = lever; try { Device = new GamePadDevice(padNumber, directInput); } catch { throw new NoDeviceException(padNumber + "番パッドの生成に失敗"); } }
protected override void Cleanup() { _subsysKeyboard?.Dispose(); _subsysKeyboard = null; _subsysMouse?.Dispose(); _subsysMouse = null; di?.Dispose(); di = null; base.Cleanup(); }
public static void Close() { if (m_mouse != null) { m_mouse.Dispose(); m_mouse = null; } if (m_directInput != null) { m_directInput.Dispose(); m_directInput = null; } }
private Joystick connectToJoystick(DirectInput directInput) { Joystick retVal = null; DeviceInstance currentInstance = GetJoystickInstance(directInput); while(currentInstance == null) { currentInstance = GetJoystickInstance(directInput); } mLogger.InfoFormat("Gamepad Connected. Name: {0}",currentInstance.ProductName); retVal = new Joystick(directInput, currentInstance.InstanceGuid); return retVal; }
public GamepadHook() { var input = new DirectInput(); var devices = input.GetDevices(); Joysticks = devices .Where(x => x.Type != DeviceType.Keyboard) .Select(x => new Joystick(input, x.InstanceGuid)).ToList(); foreach (var joystick in Joysticks) { joystick.Properties.BufferSize = 128; joystick.Acquire(); } }
static void MainForJoystick() { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) joystickGuid = deviceInstance.InstanceGuid; // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) joystickGuid = deviceInstance.InstanceGuid; // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { Console.WriteLine("No joystick/Gamepad found."); Console.ReadKey(); Environment.Exit(1); } // Instantiate the joystick var joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); // Query all suported ForceFeedback effects var allEffects = joystick.GetEffects(); foreach (var effectInfo in allEffects) Console.WriteLine("Effect available {0}", effectInfo.Name); // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); // Poll events from joystick while (true) { joystick.Poll(); var datas = joystick.GetBufferedData(); foreach (var state in datas) Console.WriteLine(state); } }
public Joystick checkDevices() { SharpDX.DirectInput.DirectInput directInput = new SharpDX.DirectInput.DirectInput(); var devices = directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly); Console.WriteLine("Wykryłem następujące urządzenia:"); foreach (DeviceInstance instance in devices) { Console.WriteLine(instance.InstanceName); } Joystick joystick = new Joystick(directInput, devices[0].InstanceGuid); return(joystick); }
private Keyboard StartKeyboard() { var dirInput = new SharpDX.DirectInput.DirectInput(); var allDevices = dirInput.GetDevices(); Keyboard keyboard = null; foreach (var item in allDevices) { if (SharpDX.DirectInput.DeviceType.Keyboard == item.Type) { keyboard = new SharpDX.DirectInput.Keyboard(dirInput); keyboard.Acquire(); } } return(keyboard); }
/// <summary> /// Function to perform the creation of the DirectInput joystick object. /// </summary> /// <param name="directInput">The direct input interface.</param> /// <param name="deviceInfo">The device information for the gaming device to use.</param> /// <returns>The DirectInput joystick object.</returns> private DI.Joystick CreateJoystick(DI.DirectInput directInput, DirectInputDeviceInfo deviceInfo) { var result = new DI.Joystick(directInput, deviceInfo.InstanceGuid); IntPtr mainWindow = FindMainApplicationWindow(); if (mainWindow == IntPtr.Zero) { // We have no main window, and DI requires one, so we need to kill this. throw new InvalidOperationException(Resources.GORINP_ERR_DI_COULD_NOT_FIND_APP_WINDOW); } result.SetCooperativeLevel(mainWindow, DI.CooperativeLevel.Foreground | DI.CooperativeLevel.NonExclusive); result.Properties.AxisMode = DI.DeviceAxisMode.Absolute; // Set up dead zones. foreach (GorgonGamingDeviceAxis axis in Axis) { // Skip the throttle. Dead zones on the throttle don't work too well for regular joysticks. // Game pads may be another story, but the user can manage those settings if required. if (axis.Axis == GamingDeviceAxis.Throttle) { continue; } GorgonGamingDeviceAxisInfo info = Info.AxisInfo[axis.Axis]; DI.ObjectProperties properties = result.GetObjectPropertiesById(_info.AxisMappings[axis.Axis]); if (properties == null) { continue; } // Set a 0 dead zone. properties.DeadZone = 0; // Make the dead zone 10% of the range for all axes. float deadZone = axis.Axis == GamingDeviceAxis.Throttle ? 0.02f : 0.10f; int deadZoneActual = (int)(info.Range.Range * deadZone); axis.DeadZone = new GorgonRange(info.DefaultValue - deadZoneActual, info.DefaultValue + deadZoneActual); } return(result); }
public Input(Game game, IntPtr handle) : base(game, -10000) { _directInput = new DirectInput(); _keyboard = new Keyboard(_directInput); _keyboard.Properties.BufferSize = 256; _keyboard.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); _mouse = new Mouse(_directInput); _mouse.Properties.AxisMode = DeviceAxisMode.Relative; _mouse.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); var devices = _directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices); if (devices.Count > 0) { _joystick = new Joystick(_directInput, devices[0].InstanceGuid); _joystick.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); } }
byte[] Rumble = new byte[8]; //who cares, just compatibility public Form1() { directInput = new DirectInput(); x360Bus = new DS4Windows.X360Device(); runningController = null; runningControllerGuid = Guid.Empty; joystick = null; lastState = null; updateThread = null; aquired = false; xbus_opened = false; xinput_plugged = false; Array.Clear(xinputData, 0, xinputData.Length); xinput_as_360_buttons = false; InitializeComponent(); }
public string[] FindJoysticks() { var ret = new string[]{}; try { var dinput = new DirectInput(); var r = dinput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly); if (r != null) { ret = r.Select(device => device.InstanceName + "|" + device.InstanceGuid.ToString()).ToArray(); } } catch (Exception ex) { Logger.LogExceptionToFile(ex); } return ret; }
public TSOForm(TSOConfig tso_config, string[] args) { this.tso_config = tso_config; InitializeComponent(); this.ClientSize = tso_config.ClientSize; this.DragDrop += new DragEventHandler(form_OnDragDrop); this.DragOver += new DragEventHandler(form_OnDragOver); this.UserResized += delegate(Object sender, EventArgs e) { userResized = true; }; this.viewer = new Viewer(); viewer.ScreenColor = tso_config.ScreenColor; this.fig_form = new FigureForm(); if (viewer.InitializeApplication(this, tso_config)) { viewer.figures.FigureEvent += delegate(object sender, EventArgs e) { Figure fig; if (viewer.figures.TryGetFigure(out fig)) fig_form.SetFigure(fig); else fig_form.Clear(); }; viewer.Camera.SetTranslation(tso_config.Position); foreach (string arg in args) viewer.figures.LoadAnyFile(arg, true); if (viewer.figures.Count == 0) viewer.figures.LoadAnyFile(Path.Combine(save_path, @"system.tdcgsav.png"), true); //this.timer1.Enabled = true; } directInput = new DirectInput(); keyboard = new Keyboard(directInput); keyboard.Acquire(); keyboardState = keyboard.GetCurrentState(); }
public Manual() { // Initialize DirectInput var directInput = new DirectInput(); // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) joystickGuid = deviceInstance.InstanceGuid; // If Gamepad not found, look for a Joystick if (joystickGuid == Guid.Empty) foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) joystickGuid = deviceInstance.InstanceGuid; // If Joystick not found, throws an error if (joystickGuid != Guid.Empty) { //fix running code without controller //Environment.Exit(1); // Instantiate the joystick joystick = new Joystick(directInput, joystickGuid); Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); // Query all suported ForceFeedback effects var allEffects = joystick.GetEffects(); foreach (var effectInfo in allEffects) Console.WriteLine("Effect available {0}", effectInfo.Name); // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); ControllerOn = true; } }
//*******************************************************// // METHODS // //*******************************************************// public static void Initialize() { if (IsInitialized) return; _DirectInput = new DirectInput(); _Mouse = new SharpDX.DirectInput.Mouse(_DirectInput); _Mouse.Properties.AxisMode = DeviceAxisMode.Relative; try { _Mouse.Acquire(); } catch (SharpDX.SharpDXException) { Console.WriteLine("Error: Failed to aquire mouse !"); return; } IsInitialized = true; }
public bool Initialize(IntPtr hwnd, int screenWidth, int screenHeight) { try { this.screenWidth = screenWidth; this.screenHeight = screenHeight; mouseX = 0; mouseY = 0; directInput = new SharpDX.DirectInput.DirectInput(); keyboard = new Keyboard(directInput); keyboard.SetCooperativeLevel(hwnd, CooperativeLevel.Background | CooperativeLevel.NonExclusive); keyboard.Acquire(); mouse = new Mouse(directInput); mouse.SetCooperativeLevel(hwnd, CooperativeLevel.Background | CooperativeLevel.NonExclusive); mouse.Acquire(); } catch { return(false); } return(true); }
public LedWizEngine() { var directInput = new SharpDX.DirectInput.DirectInput(); var joystickDeviceInstance = directInput.GetDevices().FirstOrDefault(x => x.Type == SharpDX.DirectInput.DeviceType.Joystick);//FIX THIS to be more specific! currently it'll take the first joystick it finds... this is dumb. if (joystickDeviceInstance == null) { throw new LedWizDeviceNotFoundException(); } _joystick = new SharpDX.DirectInput.Joystick(directInput, joystickDeviceInstance.InstanceGuid); _joystick.Properties.BufferSize = 128; _hardwarePoller.WorkerSupportsCancellation = true; _hardwarePoller.WorkerReportsProgress = false; _hardwarePoller.DoWork += _hardwarePoller_DoWork; _hardwarePoller.RunWorkerCompleted += _hardwarePoller_RunWorkerCompleted; _ledWiz = new LEDWiz(IntPtr.Zero); _ledWiz.StartupLighting(); }
public DirectXJoystick(InputManager creator, MDI.DirectInput device, bool buffered, MDI.CooperativeLevel coopSettings) { Creator = creator; this._directInput = device; IsBuffered = buffered; this._coopSettings = coopSettings; Type = InputType.Joystick; EventListener = null; this._joyInfo = (JoystickInfo)((DirectXInputManager)Creator).CaptureDevice <Joystick>(); if (this._joyInfo == null) { throw new Exception("No devices match requested type."); } this._deviceGuid = this._joyInfo.DeviceId; Vendor = this._joyInfo.Vendor; DeviceID = this._joyInfo.Id.ToString(); }
public DirectXMouse(InputManager creator, MDI.DirectInput device, bool buffered, MDI.CooperativeLevel coopSettings) { Creator = creator; this._directInput = device; IsBuffered = buffered; this._coopSettings = coopSettings; Type = InputType.Mouse; EventListener = null; this._msInfo = (MouseInfo)((DirectXInputManager)Creator).CaptureDevice <Mouse>(); if (this._msInfo == null) { throw new Exception("No devices match requested type."); } this._hideMouse = ((DirectXInputManager)creator).HideMouse; Log.Debug("DirectXMouse device created."); }
private IEnumerable <ILowLevelInputDevice> GetGenericGamepads(IEnumerable <DeviceInstance> gamepads, SharpDX.DirectInput.DirectInput directInput) { var inputDevices = new List <ILowLevelInputDevice>(); for (int i = 0; i < gamepads.Count(); i++) { DeviceInstance deviceInstance = gamepads.ElementAt(i); SharpDX.DirectInput.Device device = new Joystick(directInput, deviceInstance.InstanceGuid); var inputDevice = new LowLevelInputDevice() { DiscoveryApi = InputApi.DirectInput, DI_InstanceGUID = deviceInstance.InstanceGuid, DI_InstanceName = deviceInstance.InstanceName.Trim('\0'), DI_ProductName = deviceInstance.ProductName.Trim('\0'), DI_ProductGUID = deviceInstance.ProductGuid, DI_DeviceType = DeviceType.Gamepad, DI_EnumerationNumber = i, }; try { inputDevice.DI_InterfacePath = device.Properties.InterfacePath.Trim('\0'); inputDevice.DI_JoystickID = device.Properties.JoystickId; inputDevice.DI_ProductID = device.Properties.ProductId; inputDevice.DI_VendorID = device.Properties.VendorId; } catch (SharpDXException) { inputDevice.DI_JoystickID = null; inputDevice.DI_InterfacePath = null; } finally { inputDevices.Add(inputDevice); } } return(inputDevices); }
/// <summary> /// Acquires, finds and evaluates all of the currently available joysticks. keyboards and /// other valid input devices. /// </summary> private void GetConnectedControllers() { // Instantiate the DirectInput adapter. _directInputAdapter = new SharpDX.DirectInput.DirectInput(); // Allocate a list of controllers. _dInputControllers = new List <DInputController>(); // Allocate a list of device instances. List <DeviceInstance> dInputDevices = new List <DeviceInstance>(); // Acquire all DInput devices. dInputDevices.AddRange(_directInputAdapter.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly)); // Acquire and initialize each device. foreach (DeviceInstance dInputDevice in dInputDevices) { // Filter devices to initialize by type. if (dInputDevice.Type == DeviceType.Joystick) { _dInputControllers.Add(SetupController(dInputDevice)); } else if (dInputDevice.Type == DeviceType.Gamepad) { _dInputControllers.Add(SetupController(dInputDevice)); } else if (dInputDevice.Type == DeviceType.Keyboard) { _dInputControllers.Add(SetupController(dInputDevice)); } else if (dInputDevice.Type == DeviceType.Mouse) { _dInputControllers.Add(SetupController(dInputDevice)); } } }
public Joystick(DirectInput directInput, Guid deviceGuid) : base(directInput, deviceGuid) { }
public Subsystem_Input_Keyboard(SharpDX.DirectInput.DirectInput di) { var k = new Keyboard(di); base.Initialize(k); }
public DirectInputInputFactory() { _nativeDirectInput = new SharpDX.DirectInput.DirectInput(); }
public DirectInputMouse(SharpDX.DirectInput.DirectInput nativeDirectInput) { _nativeMouse = new Mouse(nativeDirectInput); _nativeMouse.Acquire(); _previousMouseState = _nativeMouse.GetCurrentState(); }
public Keyboard(DirectInput directInput) : base(directInput, DeviceGuid.SysKeyboard) { }
protected CustomDevice(DirectInput directInput, Guid deviceGuid) : base(directInput, deviceGuid) { var dataFormat = GetDataFormat(); SetDataFormat(dataFormat); }
public Subsystem_Input_Mouse(SharpDX.DirectInput.DirectInput di) { var k = new Mouse(di); base.Initialize(k); }
public void ThreadStart() { byte[] keybdState = new byte[256]; GetKeyboardState(keybdState); NumLock = (keybdState[(int)VK.VK_NUMLOCK] & 1) != 0; CapsLock = (keybdState[(int)VK.VK_CAPITAL] & 1) != 0; ScrollLock = (keybdState[(int)VK.VK_SCROLL] & 1) != 0; Shift = (keybdState[(int)VK.VK_SHIFT] & 0x80) != 0; LShift = (keybdState[(int)VK.VK_LSHIFT] & 0x80) != 0; RShift = (keybdState[(int)VK.VK_RSHIFT] & 0x80) != 0; Ctrl = (keybdState[(int)VK.VK_CONTROL] & 0x80) != 0; LCtrl = (keybdState[(int)VK.VK_LCONTROL] & 0x80) != 0; RCtrl = (keybdState[(int)VK.VK_RCONTROL] & 0x80) != 0; Alt = (keybdState[(int)VK.VK_MENU] & 0x80) != 0; LAlt = (keybdState[(int)VK.VK_LMENU] & 0x80) != 0; RAlt = (keybdState[(int)VK.VK_RMENU] & 0x80) != 0; var directInput = new SharpDX.DirectInput.DirectInput(); var keybdGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Keyboard, DeviceEnumerationFlags.AllDevices)) { keybdGuid = deviceInstance.InstanceGuid; } if (keybdGuid == Guid.Empty) { Environment.Exit(1); } var keybd = new SharpDX.DirectInput.Keyboard(directInput); keybd.Properties.BufferSize = 128; keybd.Acquire(); string keys = ""; VK vk = 0x00; KeyboardUpdate Scan = new KeyboardUpdate(); Stopwatch holdInSW = new Stopwatch(); Stopwatch holdInIntervalSW = new Stopwatch(); holdInSW.Start(); holdInIntervalSW.Start(); var dwThread = Native.WinAPI.GetCurrentThreadId(); while (true) { Thread.Sleep(1); Native.DesktopSwitch.PollAutoDesktopThreadSwitch(dwThread); keybd.Poll(); var datas = keybd.GetBufferedData(); if (datas.Length != 0) { holdInSW.Restart(); } else if (holdInSW.Elapsed > PressedInHoldTime && Scan.IsPressed) { if (holdInIntervalSW.Elapsed > PressedInInterval) { HandleKey(keys, vk, Scan.Key, Scan.IsPressed); holdInIntervalSW.Restart(); } } foreach (var state in datas) { /*if (state.Key == Key.F12) { * Hooks.RemoveHooks(); * Environment.Exit(0); * Debug.Assert(false); * var a = (1 + 9) - 10; * Debug.WriteLine((15 / a)); * return; * }*/ if (state.IsPressed) { switch (state.Key) { case Key.Capital: CapsLock = !CapsLock; break; case Key.NumberLock: NumLock = !NumLock; break; case Key.ScrollLock: ScrollLock = !ScrollLock; break; } } switch (state.Key) { case Key.RightShift: RShift = state.IsPressed; break; case Key.LeftShift: LShift = state.IsPressed; break; case Key.LeftControl: LCtrl = state.IsPressed; break; case Key.RightControl: RCtrl = state.IsPressed; break; case Key.LeftAlt: LAlt = state.IsPressed; break; case Key.RightAlt: RAlt = state.IsPressed; break; } Shift = LShift || RShift; Ctrl = LCtrl || RCtrl; Alt = LAlt || RAlt; byte[] keyState = new byte[256]; if (CapsLock) { keyState[(int)VK.VK_CAPITAL] = 0x01; } if (NumLock) { keyState[(int)VK.VK_NUMLOCK] = 0x01; } if (ScrollLock) { keyState[(int)VK.VK_SCROLL] = 0x01; } if (Shift) { keyState[(int)VK.VK_SHIFT] = 0x80; } if (Ctrl) { keyState[(int)VK.VK_CONTROL] = 0x80; } if (Alt) { keyState[(int)VK.VK_MENU] = 0x80; } keys = ScancodeToUnicode(state.Key, keyState); vk = ScancodeToVKCode(state.Key); Scan = state; HandleKey(keys, vk, Scan.Key, Scan.IsPressed); } } }
public void CaptureJoysticks() { // Initialize DirectInput var directInput = new DirectInput(); // Find all joysticks connected to the system IList<DeviceInstance> connectedJoysticks = new List<DeviceInstance>(); // - look for gamepads foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) { connectedJoysticks.Add(deviceInstance); } // - look for joysticks foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) { connectedJoysticks.Add(deviceInstance); } // Use the two first joysticks found if (connectedJoysticks.Count >= 1) { joystick1 = new Joystick(directInput, connectedJoysticks[0].InstanceGuid); Joystick1DeviceName = connectedJoysticks[0].InstanceName; joystick1.Acquire(); } if (connectedJoysticks.Count >= 2) { joystick2 = new Joystick(directInput, connectedJoysticks[1].InstanceGuid); Joystick2DeviceName = connectedJoysticks[1].InstanceName; joystick2.Acquire(); } }