From 4ff239aa0ba4ff867c37530b65cb1e24dbc10551 Mon Sep 17 00:00:00 2001 From: David Meyer Date: Fri, 15 Mar 2019 17:34:09 -0500 Subject: [PATCH] Remove periods from controller descriptions. --- src/JsPie.Plugins/Keyboard/KeyboardPlugin.cs | 458 +++++++++---------- src/JsPie.Plugins/Ps3/Ps3Plugin.cs | 178 +++---- src/JsPie.Plugins/VJoy/VJoyPlugin.cs | 364 +++++++-------- 3 files changed, 500 insertions(+), 500 deletions(-) diff --git a/src/JsPie.Plugins/Keyboard/KeyboardPlugin.cs b/src/JsPie.Plugins/Keyboard/KeyboardPlugin.cs index 830eff9..edec311 100644 --- a/src/JsPie.Plugins/Keyboard/KeyboardPlugin.cs +++ b/src/JsPie.Plugins/Keyboard/KeyboardPlugin.cs @@ -1,229 +1,229 @@ -using System; -using System.Collections.Generic; -using JsPie.Core; -using System.Linq; -using static JsPie.Plugins.Keyboard.KeyboardApi; - -namespace JsPie.Plugins.Keyboard -{ - public class KeyboardPlugin : IInputPlugin, IOutputPlugin, IDisposable - { - private static ControllerId ControllerId; - private static List Controls; - - private static ControllerInfo ControllerInfo; - - static KeyboardPlugin() - { - ControllerId = new ControllerId("keyboard"); - - Controls = new List - { - Key("backSpace", 8), - Key("tab", 9), - Key("enter", 13), - Key("shift", 16), - Key("ctrl", 17), - Key("alt", 18), - Key("pause", 19), - Key("capsLock", 20), - Key("esc", 27), - Key("space", 32), - Key("pageUp", 33), - Key("pageDown", 34), - Key("end", 35), - Key("home", 36), - Key("left", 37), - Key("up", 38), - Key("right", 39), - Key("down", 40), - Key("insert", 45), - Key("delete", 46), - - Key("zero", 48), - Key("one", 49), - Key("two", 50), - Key("three", 51), - Key("four", 52), - Key("five", 53), - Key("six", 54), - Key("seven", 55), - Key("eight", 56), - Key("nine", 57), - - Key("a", 65), - Key("b", 66), - Key("c", 67), - Key("d", 68), - Key("e", 69), - Key("f", 70), - Key("g", 71), - Key("h", 72), - Key("i", 73), - Key("j", 74), - Key("k", 75), - Key("l", 76), - Key("m", 77), - Key("n", 78), - Key("o", 79), - Key("p", 80), - Key("q", 81), - Key("r", 82), - Key("s", 83), - Key("t", 84), - Key("u", 85), - Key("v", 86), - Key("w", 87), - Key("x", 88), - Key("y", 89), - Key("z", 90), - - Key("lwin", 91), - Key("rwin", 92), - Key("select", 93), - Key("numpad0", 96), - Key("numpad1", 97), - Key("numpad2", 98), - Key("numpad3", 99), - Key("numpad4", 100), - Key("numpad5", 101), - Key("numpad6", 102), - Key("numpad7", 103), - Key("numpad8", 104), - Key("numpad9", 105), - Key("ultiply", 106), - Key("add", 107), - Key("subtract", 109), - Key("decimal", 110), - Key("divide", 111), - Key("f1", 112), - Key("f2", 113), - Key("f3", 114), - Key("f4", 115), - Key("f5", 116), - Key("f6", 117), - Key("f7", 118), - Key("f8", 119), - Key("f9", 120), - Key("f10", 121), - Key("f11", 122), - Key("f12", 123), - Key("numLock", 144), - Key("scrollLock", 145), - Key("lshift", 160), - Key("rshift", 161), - Key("lctrl", 162), - Key("rctrl", 163), - Key("lalt", 164), - Key("ralt", 165), - Key("semicolon", 186), - Key("equals", 187), - Key("comma", 188), - Key("dash", 189), - Key("period", 190), - Key("forwardSlash", 191), - Key("tilde", 192), - Key("openBracket", 219), - Key("backSlash", 220), - Key("closeBraket", 221), - Key("apostrophe", 222), - Key("fn", 255) - }; - - for (int i = 0; i <= 255; i++) - { - if (!Controls.Any(c => c.KeyCode == i)) - { - Controls.Add(Key($"keycode${i}", i)); - } - } - - ControllerInfo = new ControllerInfo(ControllerId.Name, 1, "The keyboard.", Controls.Select(c => c.ControlInfo)); - } - - private static KeyboardControlInfo Key(string name, int keyCode, string description = null) - { - return new KeyboardControlInfo(ControllerId, new ControlInfo(name, description), keyCode); - } - - - private readonly KeyboardControl[] _controlsByKeyCode; - private readonly Dictionary _controlsByName; - private readonly uint _mark; - private readonly KeyboardHook _hook; - private readonly bool[] _keyState; - - public KeyboardPlugin() - { - _controlsByKeyCode = new KeyboardControl[Controls.Max(c => c.KeyCode) + 1]; - _controlsByName = new Dictionary(); - foreach (var controlInfo in Controls) - { - var control = new KeyboardControl(controlInfo); - _controlsByKeyCode[controlInfo.KeyCode] = control; - _controlsByName[controlInfo.ControlId.Name] = control; - } - - _mark = (uint)new Random().Next(0, int.MaxValue); - _hook = new KeyboardHook(_mark); - _keyState = new bool[Controls.Max(c => c.KeyCode) + 1]; - - _hook.KeyboardHookEvent += OnKeyboardHookEvent; - } - - public void Dispose() - { - _hook.Dispose(); - } - - public IEnumerable GetControllers() - { - yield return ControllerInfo; - } - - public event ControlEventHandler ControlEvent; - public event ControlEventsHandler ControlEvents; - - public void ProcessEvents(IEnumerable events) - { - foreach (var @event in events) - { - if (@event.ControlId.ControllerId.Name != ControllerId.Name) - continue; - - KeyboardControl control; - if (!_controlsByName.TryGetValue(@event.ControlId.Name, out control)) - continue; - - var keyCode = control.KeyboardControlInfo.KeyCode; - var keyState = @event.Value != 0; - control.KeyState = keyState; - keybd_event((byte)keyCode, 0, keyState ? 0 : KEYEVENTF_KEYUP, _mark); - } - } - - private void OnKeyboardHookEvent(uint keyCode, bool value) - { - if (keyCode >= _controlsByKeyCode.Length) - return; - - var control = _controlsByKeyCode[keyCode]; - if (control == null) - return; - - var lastValue = control.KeyState; - if (value == lastValue) - return; - - control.KeyState = value; - - var @event = new ControlEvent(control.KeyboardControlInfo.ControlId, value ? 1f : 0f); - - var handler = ControlEvent; - if (handler != null) - { - handler(this, @event); - } - } - } -} +using System; +using System.Collections.Generic; +using JsPie.Core; +using System.Linq; +using static JsPie.Plugins.Keyboard.KeyboardApi; + +namespace JsPie.Plugins.Keyboard +{ + public class KeyboardPlugin : IInputPlugin, IOutputPlugin, IDisposable + { + private static ControllerId ControllerId; + private static List Controls; + + private static ControllerInfo ControllerInfo; + + static KeyboardPlugin() + { + ControllerId = new ControllerId("keyboard"); + + Controls = new List + { + Key("backSpace", 8), + Key("tab", 9), + Key("enter", 13), + Key("shift", 16), + Key("ctrl", 17), + Key("alt", 18), + Key("pause", 19), + Key("capsLock", 20), + Key("esc", 27), + Key("space", 32), + Key("pageUp", 33), + Key("pageDown", 34), + Key("end", 35), + Key("home", 36), + Key("left", 37), + Key("up", 38), + Key("right", 39), + Key("down", 40), + Key("insert", 45), + Key("delete", 46), + + Key("zero", 48), + Key("one", 49), + Key("two", 50), + Key("three", 51), + Key("four", 52), + Key("five", 53), + Key("six", 54), + Key("seven", 55), + Key("eight", 56), + Key("nine", 57), + + Key("a", 65), + Key("b", 66), + Key("c", 67), + Key("d", 68), + Key("e", 69), + Key("f", 70), + Key("g", 71), + Key("h", 72), + Key("i", 73), + Key("j", 74), + Key("k", 75), + Key("l", 76), + Key("m", 77), + Key("n", 78), + Key("o", 79), + Key("p", 80), + Key("q", 81), + Key("r", 82), + Key("s", 83), + Key("t", 84), + Key("u", 85), + Key("v", 86), + Key("w", 87), + Key("x", 88), + Key("y", 89), + Key("z", 90), + + Key("lwin", 91), + Key("rwin", 92), + Key("select", 93), + Key("numpad0", 96), + Key("numpad1", 97), + Key("numpad2", 98), + Key("numpad3", 99), + Key("numpad4", 100), + Key("numpad5", 101), + Key("numpad6", 102), + Key("numpad7", 103), + Key("numpad8", 104), + Key("numpad9", 105), + Key("ultiply", 106), + Key("add", 107), + Key("subtract", 109), + Key("decimal", 110), + Key("divide", 111), + Key("f1", 112), + Key("f2", 113), + Key("f3", 114), + Key("f4", 115), + Key("f5", 116), + Key("f6", 117), + Key("f7", 118), + Key("f8", 119), + Key("f9", 120), + Key("f10", 121), + Key("f11", 122), + Key("f12", 123), + Key("numLock", 144), + Key("scrollLock", 145), + Key("lshift", 160), + Key("rshift", 161), + Key("lctrl", 162), + Key("rctrl", 163), + Key("lalt", 164), + Key("ralt", 165), + Key("semicolon", 186), + Key("equals", 187), + Key("comma", 188), + Key("dash", 189), + Key("period", 190), + Key("forwardSlash", 191), + Key("tilde", 192), + Key("openBracket", 219), + Key("backSlash", 220), + Key("closeBraket", 221), + Key("apostrophe", 222), + Key("fn", 255) + }; + + for (int i = 0; i <= 255; i++) + { + if (!Controls.Any(c => c.KeyCode == i)) + { + Controls.Add(Key($"keycode${i}", i)); + } + } + + ControllerInfo = new ControllerInfo(ControllerId.Name, 1, "The keyboard", Controls.Select(c => c.ControlInfo)); + } + + private static KeyboardControlInfo Key(string name, int keyCode, string description = null) + { + return new KeyboardControlInfo(ControllerId, new ControlInfo(name, description), keyCode); + } + + + private readonly KeyboardControl[] _controlsByKeyCode; + private readonly Dictionary _controlsByName; + private readonly uint _mark; + private readonly KeyboardHook _hook; + private readonly bool[] _keyState; + + public KeyboardPlugin() + { + _controlsByKeyCode = new KeyboardControl[Controls.Max(c => c.KeyCode) + 1]; + _controlsByName = new Dictionary(); + foreach (var controlInfo in Controls) + { + var control = new KeyboardControl(controlInfo); + _controlsByKeyCode[controlInfo.KeyCode] = control; + _controlsByName[controlInfo.ControlId.Name] = control; + } + + _mark = (uint)new Random().Next(0, int.MaxValue); + _hook = new KeyboardHook(_mark); + _keyState = new bool[Controls.Max(c => c.KeyCode) + 1]; + + _hook.KeyboardHookEvent += OnKeyboardHookEvent; + } + + public void Dispose() + { + _hook.Dispose(); + } + + public IEnumerable GetControllers() + { + yield return ControllerInfo; + } + + public event ControlEventHandler ControlEvent; + public event ControlEventsHandler ControlEvents; + + public void ProcessEvents(IEnumerable events) + { + foreach (var @event in events) + { + if (@event.ControlId.ControllerId.Name != ControllerId.Name) + continue; + + KeyboardControl control; + if (!_controlsByName.TryGetValue(@event.ControlId.Name, out control)) + continue; + + var keyCode = control.KeyboardControlInfo.KeyCode; + var keyState = @event.Value != 0; + control.KeyState = keyState; + keybd_event((byte)keyCode, 0, keyState ? 0 : KEYEVENTF_KEYUP, _mark); + } + } + + private void OnKeyboardHookEvent(uint keyCode, bool value) + { + if (keyCode >= _controlsByKeyCode.Length) + return; + + var control = _controlsByKeyCode[keyCode]; + if (control == null) + return; + + var lastValue = control.KeyState; + if (value == lastValue) + return; + + control.KeyState = value; + + var @event = new ControlEvent(control.KeyboardControlInfo.ControlId, value ? 1f : 0f); + + var handler = ControlEvent; + if (handler != null) + { + handler(this, @event); + } + } + } +} diff --git a/src/JsPie.Plugins/Ps3/Ps3Plugin.cs b/src/JsPie.Plugins/Ps3/Ps3Plugin.cs index 57f1107..369a66c 100644 --- a/src/JsPie.Plugins/Ps3/Ps3Plugin.cs +++ b/src/JsPie.Plugins/Ps3/Ps3Plugin.cs @@ -1,89 +1,89 @@ -using System; -using System.Collections.Generic; -using JsPie.Core; -using System.Linq; -using System.Threading.Tasks; - -namespace JsPie.Plugins.Ps3 -{ - public class Ps3Plugin : IInputPlugin, IDisposable - { - private static readonly ControllerId ControllerId = new ControllerId("ps3"); - - private readonly Ps3ControlSet _controlSet; - private readonly ControllerInfo _controllerInfo; - - private readonly Ps3UsbDeviceInterface _device; - private readonly Task _pollTask; - - private bool _isDisposed; - - public Ps3Plugin() - { - _controlSet = new Ps3ControlSet(ControllerId); - _controllerInfo = new ControllerInfo(ControllerId.Name, 1, "PlayStation3 controller.", _controlSet.Controls.Select(c => c.Ps3ControlInfo.ControlInfo)); - - // TODO: Multiple controllers and detect when controllers are connected / disconnected - var enumerator = new Ps3UsbDeviceEnumerator(); - var devices = enumerator.GetDevices(); - if (devices.Count == 0) - { - Console.WriteLine("No PS3 controller detected."); - return; - } - _device = new Ps3UsbDeviceInterface(devices[0]); - - _pollTask = Task.Factory.StartNew(Poll, TaskCreationOptions.LongRunning); - } - - public void Dispose() - { - if (_isDisposed) - return; - - _isDisposed = true; - - _pollTask.Wait(); - } - - public event ControlEventHandler ControlEvent; - public event ControlEventsHandler ControlEvents; - - public IEnumerable GetControllers() - { - yield return _controllerInfo; - } - - private void Poll() - { - while (!_isDisposed) - { - var data = _device.Read(); - - if (_isDisposed) - break; - - var events = (List)null; - - foreach (var control in _controlSet.Controls) - { - var @event = control.UpdateValue(data); - if (@event != null) - { - if (events == null) - events = new List(); - - events.Add(@event); - } - } - - if (events != null) - { - var handler = ControlEvents; - if (handler != null) - handler(this, events); - } - } - } - } -} +using System; +using System.Collections.Generic; +using JsPie.Core; +using System.Linq; +using System.Threading.Tasks; + +namespace JsPie.Plugins.Ps3 +{ + public class Ps3Plugin : IInputPlugin, IDisposable + { + private static readonly ControllerId ControllerId = new ControllerId("ps3"); + + private readonly Ps3ControlSet _controlSet; + private readonly ControllerInfo _controllerInfo; + + private readonly Ps3UsbDeviceInterface _device; + private readonly Task _pollTask; + + private bool _isDisposed; + + public Ps3Plugin() + { + _controlSet = new Ps3ControlSet(ControllerId); + _controllerInfo = new ControllerInfo(ControllerId.Name, 1, "PlayStation3 controller", _controlSet.Controls.Select(c => c.Ps3ControlInfo.ControlInfo)); + + // TODO: Multiple controllers and detect when controllers are connected / disconnected + var enumerator = new Ps3UsbDeviceEnumerator(); + var devices = enumerator.GetDevices(); + if (devices.Count == 0) + { + Console.WriteLine("No PS3 controller detected."); + return; + } + _device = new Ps3UsbDeviceInterface(devices[0]); + + _pollTask = Task.Factory.StartNew(Poll, TaskCreationOptions.LongRunning); + } + + public void Dispose() + { + if (_isDisposed) + return; + + _isDisposed = true; + + _pollTask.Wait(); + } + + public event ControlEventHandler ControlEvent; + public event ControlEventsHandler ControlEvents; + + public IEnumerable GetControllers() + { + yield return _controllerInfo; + } + + private void Poll() + { + while (!_isDisposed) + { + var data = _device.Read(); + + if (_isDisposed) + break; + + var events = (List)null; + + foreach (var control in _controlSet.Controls) + { + var @event = control.UpdateValue(data); + if (@event != null) + { + if (events == null) + events = new List(); + + events.Add(@event); + } + } + + if (events != null) + { + var handler = ControlEvents; + if (handler != null) + handler(this, events); + } + } + } + } +} diff --git a/src/JsPie.Plugins/VJoy/VJoyPlugin.cs b/src/JsPie.Plugins/VJoy/VJoyPlugin.cs index ba829b3..cc6fcd6 100644 --- a/src/JsPie.Plugins/VJoy/VJoyPlugin.cs +++ b/src/JsPie.Plugins/VJoy/VJoyPlugin.cs @@ -1,182 +1,182 @@ -using JsPie.Core; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using vJoyInterfaceWrap; - -namespace JsPie.Plugins.VJoy -{ - public class VJoyPlugin : IOutputPlugin, IDisposable - { - private static readonly ControllerId ControllerId = new ControllerId("vjoy"); - - private readonly VJoyControlSet _controlSet; - private readonly ControllerInfo _controllerInfo; - private readonly vJoy _joystick; - private readonly Task _task; - - private vJoy.JoystickState _state; - - private bool _isAcquired; - private bool _isDisposed; - - public VJoyPlugin() - { - _controlSet = new VJoyControlSet(ControllerId); - _controllerInfo = new ControllerInfo(ControllerId.Name, 1, "vJoy joystick.", _controlSet.Controls.Select(c => c.ControlInfo)); - - _joystick = new vJoy(); - - var state = new vJoy.JoystickState - { - bDevice = 1 - }; - - foreach (var control in _controlSet.Controls) - { - control.SetValue(ref state, 0); - } - - _state = state; - - _task = Task.Factory.StartNew(Poll, TaskCreationOptions.LongRunning); - } - - public void Dispose() - { - if (!_isDisposed) - return; - - _isDisposed = true; - - _task.Wait(); - } - - public IEnumerable GetControllers() - { - yield return _controllerInfo; - } - - public void ProcessEvents(IEnumerable events) - { - var state = _state; - - foreach (var @event in events) - { - if (@event.ControlId.ControllerId.Name != ControllerId.Name) - continue; - - var control = _controlSet.GetControlByName(@event.ControlId.Name); - if (control != null) - { - control.SetValue(ref state, @event.Value); - } - } - - _state = state; - } - - private void Poll() - { - while (!_isDisposed) - { - if (!_isAcquired) - { - if (!InitializeVJoy()) - Thread.Sleep(1000); - } - else - { - if (!FeedVJoy()) - Thread.Sleep(1000); - } - - Thread.Sleep(16); - } - - if (_isAcquired) - FreeVJoy(); - } - - private bool InitializeVJoy() - { - const int id = 1; - - // Get the driver attributes (Vendor ID, Product ID, Version Number) - if (!_joystick.vJoyEnabled()) - { - Console.WriteLine("vJoy driver not enabled; failed getting vJoy attributes."); - return false; - } - - // Get the state of the requested device - var status = _joystick.GetVJDStatus(id); - switch (status) - { - case VjdStat.VJD_STAT_OWN: - Console.WriteLine($"vJoy device {id} is already owned by this feeder."); - break; - case VjdStat.VJD_STAT_FREE: - Console.WriteLine($"vJoy device {id} is free."); - break; - case VjdStat.VJD_STAT_BUSY: - Console.WriteLine($"vJoy device {id} is already owned by another feeder. Failed acquiring device."); - return false; - case VjdStat.VJD_STAT_MISS: - Console.WriteLine($"vJoy device {id} is not installed or disabled. Failed acquiring device."); - return false; - default: - Console.WriteLine($"vJoy device {id} general error. Failed acquiring device."); - return false; - }; - - // Test if DLL matches the driver - uint dllVer = 0; - uint drvVer = 0; - bool match = _joystick.DriverMatch(ref dllVer, ref drvVer); - if (!match) - { - Console.WriteLine($"Version of vJoy driver ({drvVer:X}) does not match DLL version ({dllVer:X})"); - return false; - } - - // Acquire the target - if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(id)))) - { - Console.WriteLine($"Failed to acquire vJoy device number {id}."); - return false; - } - - _isAcquired = true; - Console.WriteLine($"Successfully acquired vJoy device number {id}."); - - return true; - } - - private bool FeedVJoy() - { - const int id = 1; - - var state = _state; - if (!_joystick.UpdateVJD(id, ref state)) - { - Console.WriteLine("Feeding vJoy device number {0} failed.", id); - _isAcquired = false; - return false; - } - - return true; - } - - private bool FreeVJoy() - { - if (!_joystick.ResetVJD(1)) - return false; - - _isAcquired = false; - return true; - } - } -} +using JsPie.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using vJoyInterfaceWrap; + +namespace JsPie.Plugins.VJoy +{ + public class VJoyPlugin : IOutputPlugin, IDisposable + { + private static readonly ControllerId ControllerId = new ControllerId("vjoy"); + + private readonly VJoyControlSet _controlSet; + private readonly ControllerInfo _controllerInfo; + private readonly vJoy _joystick; + private readonly Task _task; + + private vJoy.JoystickState _state; + + private bool _isAcquired; + private bool _isDisposed; + + public VJoyPlugin() + { + _controlSet = new VJoyControlSet(ControllerId); + _controllerInfo = new ControllerInfo(ControllerId.Name, 1, "vJoy joystick", _controlSet.Controls.Select(c => c.ControlInfo)); + + _joystick = new vJoy(); + + var state = new vJoy.JoystickState + { + bDevice = 1 + }; + + foreach (var control in _controlSet.Controls) + { + control.SetValue(ref state, 0); + } + + _state = state; + + _task = Task.Factory.StartNew(Poll, TaskCreationOptions.LongRunning); + } + + public void Dispose() + { + if (!_isDisposed) + return; + + _isDisposed = true; + + _task.Wait(); + } + + public IEnumerable GetControllers() + { + yield return _controllerInfo; + } + + public void ProcessEvents(IEnumerable events) + { + var state = _state; + + foreach (var @event in events) + { + if (@event.ControlId.ControllerId.Name != ControllerId.Name) + continue; + + var control = _controlSet.GetControlByName(@event.ControlId.Name); + if (control != null) + { + control.SetValue(ref state, @event.Value); + } + } + + _state = state; + } + + private void Poll() + { + while (!_isDisposed) + { + if (!_isAcquired) + { + if (!InitializeVJoy()) + Thread.Sleep(1000); + } + else + { + if (!FeedVJoy()) + Thread.Sleep(1000); + } + + Thread.Sleep(16); + } + + if (_isAcquired) + FreeVJoy(); + } + + private bool InitializeVJoy() + { + const int id = 1; + + // Get the driver attributes (Vendor ID, Product ID, Version Number) + if (!_joystick.vJoyEnabled()) + { + Console.WriteLine("vJoy driver not enabled; failed getting vJoy attributes."); + return false; + } + + // Get the state of the requested device + var status = _joystick.GetVJDStatus(id); + switch (status) + { + case VjdStat.VJD_STAT_OWN: + Console.WriteLine($"vJoy device {id} is already owned by this feeder."); + break; + case VjdStat.VJD_STAT_FREE: + Console.WriteLine($"vJoy device {id} is free."); + break; + case VjdStat.VJD_STAT_BUSY: + Console.WriteLine($"vJoy device {id} is already owned by another feeder. Failed acquiring device."); + return false; + case VjdStat.VJD_STAT_MISS: + Console.WriteLine($"vJoy device {id} is not installed or disabled. Failed acquiring device."); + return false; + default: + Console.WriteLine($"vJoy device {id} general error. Failed acquiring device."); + return false; + }; + + // Test if DLL matches the driver + uint dllVer = 0; + uint drvVer = 0; + bool match = _joystick.DriverMatch(ref dllVer, ref drvVer); + if (!match) + { + Console.WriteLine($"Version of vJoy driver ({drvVer:X}) does not match DLL version ({dllVer:X})"); + return false; + } + + // Acquire the target + if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(id)))) + { + Console.WriteLine($"Failed to acquire vJoy device number {id}."); + return false; + } + + _isAcquired = true; + Console.WriteLine($"Successfully acquired vJoy device number {id}."); + + return true; + } + + private bool FeedVJoy() + { + const int id = 1; + + var state = _state; + if (!_joystick.UpdateVJD(id, ref state)) + { + Console.WriteLine("Feeding vJoy device number {0} failed.", id); + _isAcquired = false; + return false; + } + + return true; + } + + private bool FreeVJoy() + { + if (!_joystick.ResetVJD(1)) + return false; + + _isAcquired = false; + return true; + } + } +}