public bool[] GetAvailableIndices() { bool[] devices = new bool[16]; if (vJoyEnabled()) { for (uint i = 0; i < 16; i++) { VjdStat status = m_joystick.GetVJDStatus(i); switch (status) { case VjdStat.VJD_STAT_FREE: devices[i] = true; break; case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_BUSY: case VjdStat.VJD_STAT_MISS: case VjdStat.VJD_STAT_UNKN: default: devices[i] = false; break; } } } return(devices); }
/** * Verify that a vJoy device is vailable */ private bool IsDeviceStatusOk(uint deviceId, VjdStat deviceStatus) { switch (deviceStatus) { case VjdStat.VJD_STAT_FREE: case VjdStat.VJD_STAT_OWN: // We can continue if the device is free or we own it return(true); case VjdStat.VJD_STAT_MISS: Debug.LogWarningFormat("vJoy Device {0} is not installed or is disabled", deviceId); SetStatus(VJoyStatus.DeviceUnavailable); return(false); case VjdStat.VJD_STAT_BUSY: Debug.LogWarningFormat("vJoy Device {0} is owned by another application", deviceId); SetStatus(VJoyStatus.DeviceOwned); return(false); default: Debug.LogError("Unknown vJoy device status error"); SetStatus(VJoyStatus.DeviceError); return(false); } }
private void CheckStatus() { // Get the state of the requested device VjdStat status = m_Interface.GetVJDStatus(m_Id); switch (status) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", m_Id); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free\n", m_Id); break; case VjdStat.VJD_STAT_BUSY: Console.WriteLine( "vJoy Device {0} is already owned by another feeder\nCannot continue\n", m_Id); return; case VjdStat.VJD_STAT_MISS: Console.WriteLine( "vJoy Device {0} is not installed or disabled\nCannot continue\n", m_Id); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", m_Id); return; } ; }
private void InitJoystick() { lock (lockObj) { // Verify the vJoy driver is enabled. if (!VirtualJoystick.vJoyEnabled()) { throw new VJoyNotEnabledException("vJoy is not enabled! Please install and enable vJoy!"); } // Get the state of the requested device. VjdStat Status = VirtualJoystick.GetVJDStatus(JoystickID); switch (Status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: case VjdStat.VJD_STAT_MISS: default: throw new VJoyAccessException("Cannot access vJoy! Code: " + Status.ToString()); } ; // Acquire the target joystick. if (!VirtualJoystick.AcquireVJD(JoystickID)) { throw new VJoyAcquisitionException("Could not acquire vJoy with ID: " + JoystickID.ToString()); } // Open the Stream Deck device. try { Deck = StreamDeck.OpenDevice(); } catch (Exception ex) { //Catch the internal StreamDeck error and handle it our way. Deck = null; #if DEBUG Console.WriteLine(ex.ToString()); #endif } if (Deck == null || !Deck.IsConnected) { throw new StreamDeckAccessException("Stream Deck could not be opened!"); } // Set the brightness of the keys. Deck.SetBrightness(100); // Register the key pressed event handler. Deck.KeyStateChanged += StreamDeckKeyPressed; } ReloadButtonImages(); }
public DeviceInformation(int deviceId, string name, Guid productGuid, VjdStat status) { Id = deviceId; _name = name; Guid = productGuid; Status = status; }
const int PULSE_LENGTH = 60; //ms public ButtonProcessor(int multiplier, int holdThresholdStart, int holdThresholdStop, OutputButton outputButton) { _multiplier = multiplier; _holdThresholdStart = holdThresholdStart; _holdThresholdStop = holdThresholdStop; _vJoyId = outputButton.VJoyDevice; _vJoyButtonNumber = outputButton.VJoyItem; _joystick = new vJoy(); if (!_joystick.vJoyEnabled()) { Debug.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); } else { Debug.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", _joystick.GetvJoyManufacturerString(), _joystick.GetvJoyProductString(), _joystick.GetvJoySerialNumberString()); } // Acquire the target VjdStat status = _joystick.GetVJDStatus(_vJoyId); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_vJoyId)))) { Debug.WriteLine("Failed to acquire vJoy device number {0}.", _vJoyId); return; } else { Debug.WriteLine("Acquired: vJoy device number {0}.", _vJoyId); } _joystick.ResetVJD(_vJoyId); }
readonly long BUTTON_FILTER = 0; // Ignore new button presses less than this (ms) public AxisProcessor(int axisSensitivity, OutputAxis outputAxis) { Debug.WriteLine("Multiplier is {0}", axisSensitivity); _sensitivity = axisSensitivity; _vJoyId = outputAxis.VJoyDevice; _vJoyAxisNumber = outputAxis.VJoyItem; _joystick = new vJoy(); if (!_joystick.vJoyEnabled()) { Debug.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); } else { Debug.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", _joystick.GetvJoyManufacturerString(), _joystick.GetvJoyProductString(), _joystick.GetvJoySerialNumberString()); } // Acquire the target (Not currently used really...) VjdStat status = _joystick.GetVJDStatus(_vJoyId); Debug.WriteLine("vJoy Status: " + status.ToString()); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_vJoyId)))) { Debug.WriteLine("Failed to acquire vJoy device number {0}.", _vJoyId); } _joystick.GetVJDAxisMax(_vJoyId, (HID_USAGES)_vJoyAxisNumber, ref _maxAxisValue); Debug.WriteLine("Max value of VJID {0} axis {1} is {2}", _vJoyId, (HID_USAGES)_vJoyAxisNumber, _maxAxisValue); Centre(); }
public static ObservableCollection <OutputChannel> GetOutputAxes() { ObservableCollection <OutputChannel> outputChannels = new(); vJoy joystick = new(); int output_id = 0; for (uint vjoy_id = 1; vjoy_id <= 16; vjoy_id++) { // Axes VjdStat status = joystick.GetVJDStatus(vjoy_id); if (status == VjdStat.VJD_STAT_FREE) { foreach (HID_USAGES axis in Enum.GetValues(typeof(HID_USAGES))) { if (joystick.GetVJDAxisExist(vjoy_id, axis)) { outputChannels.Add(new OutputAxis { VJoyId = output_id++, VJoyDevice = vjoy_id, VJoyItem = (uint)axis }); } } } } return(outputChannels); }
private vJoy initVjoy(uint id) { var joystick = new vJoy(); var iReport = new vJoy.JoystickState(); // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(id); /*switch (status) * { * case VjdStat.VJD_STAT_OWN: * MessageBox.Show(string.Format("vJoy Device {0} is already owned by this feeder\n", id)); * break; * case VjdStat.VJD_STAT_FREE: * MessageBox.Show(string.Format("vJoy Device {0} is free\n", id)); * break; * case VjdStat.VJD_STAT_BUSY: * MessageBox.Show(string.Format("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id)); * return joystick; * case VjdStat.VJD_STAT_MISS: * MessageBox.Show(string.Format("vJoy Device {0} is not installed or disabled\nCannot continue\n", id)); * return joystick; * default: * MessageBox.Show(string.Format("vJoy Device {0} general error\nCannot continue\n", id)); * return joystick; * }*/ bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); if (joystick.AcquireVJD(id) == false) { MessageBox.Show("Could not acquire vJoy " + id); } Console.WriteLine(AxisX); return(joystick); }
public void init_vjoy() { try { joystick = new vJoy(); if (!joystick.vJoyEnabled()) { MessageBox.Show("vJoy driver not enabled: Failed Getting vJoy attributes."); return; } VjdStat status = joystick.GetVJDStatus(id); // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); //if (match) //MessageBox.Show("Version of Driver Matches DLL Version ("+ DllVer.ToString()+")"); //else //MessageBox.Show("Version of Driver (" + DrvVer.ToString() + ") does NOT match DLL Version (" + DllVer.ToString() + ")"); joystick.AcquireVJD(id); } catch { MessageBox.Show("vjoy failed to init"); } }
public VJoyDevice(uint id) { device = new vJoy(); this.id = id; if (!device.vJoyEnabled()) { throw new Exception("vJoy driver not enabled."); } VjdStat status = device.GetVJDStatus(id); if (status == VjdStat.VJD_STAT_BUSY) { throw new Exception("vJoy device is already in use."); } else if (status == VjdStat.VJD_STAT_MISS) { throw new Exception("vJoy device is not installed or disabled."); } if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!device.AcquireVJD(id)))) { throw new Exception("Failed to acquire vJoy device " + id + "."); } }
void OnEnable() { vjoy = new vJoy(); if (!vjoy.vJoyEnabled()) { SetStatus(VJoyStatus.NotInstalled); enabled = false; return; } uint DllVer = 0, DrvVer = 0; bool match = vjoy.DriverMatch(ref DllVer, ref DrvVer); if (match) { Debug.LogFormat("vJoy Driver Version Matches vJoy DLL Version ({0:X})", DllVer); } else { Debug.LogErrorFormat("vJoy Driver Version ({0:X}) does NOT match vJoy DLL Version ({1:X})", DrvVer, DllVer); SetStatus(VJoyStatus.VersionMismatch); enabled = false; return; } VjdStat deviceStatus = vjoy.GetVJDStatus(deviceId); VjdStat secondaryDeviceStatus = vjoy.GetVJDStatus(secondaryDeviceId); if (!IsDeviceStatusOk(deviceId, deviceStatus) || !IsDeviceStatusOk(secondaryDeviceId, secondaryDeviceStatus)) { enabled = false; return; } if (!IsDeviceValid(deviceId)) { Debug.LogError("vJoy device is not configured correctly"); SetStatus(VJoyStatus.DeviceMisconfigured); enabled = false; return; } if (!IsSecondaryDeviceValid(deviceId)) { Debug.LogError("Secondary vJoy device is not configured correctly"); SetStatus(VJoyStatus.DeviceMisconfigured); enabled = false; return; } if (!AcquireDevice(deviceId, deviceStatus) || !AcquireDevice(secondaryDeviceId, secondaryDeviceStatus)) { enabled = false; return; } SetStatus(VJoyStatus.Ready); }
public static void InitializeVJoyDevice(uint vJoyID, HID_USAGES axis) { lock (vJoyLocker) { if (vJoyInitialized) { return; } vJoyInitialized = true; AppLogger.LogToGui("Initializing VJoy virtual joystick driver via vJoyInterface.dll interface", false); try { if (vJoyObj == null) { vJoyObj = new VJoy(); } if (vJoyObj.vJoyEnabled() && vJoyObj.GetVJDAxisExist(vJoyID, axis)) { AppLogger.LogToGui("Connection to VJoy virtual joystick established", false); AppLogger.LogToGui($"VJoy driver. Vendor={vJoyObj.GetvJoyManufacturerString()} Product={vJoyObj.GetvJoyProductString()} Version={vJoyObj.GetvJoySerialNumberString()} Device#={vJoyID} Axis={axis}", false); // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; if (!vJoyObj.DriverMatch(ref DllVer, ref DrvVer)) { AppLogger.LogToGui("WARNING. VJoy version of Driver {DrvVer}) does not match interface DLL Version {DllVer}. This may lead to unexpected problems or crashes. Update VJoy driver and vJoyInterface.dll", false); } VjdStat status = vJoyObj.GetVJDStatus(vJoyID); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!vJoyObj.AcquireVJD(vJoyID)))) { vJoyAvailable = false; AppLogger.LogToGui("ERROR. Failed to acquire vJoy device# {vJoyID}. Use another VJoy device or make sure there are no other VJoy feeder apps using the same device", false); } else { //vJoyObj.GetVJDAxisMax(vJoyID, axis, ref vJoyAxisMaxValue); //AppLogger.LogToGui($"VJoy axis {axis} max value={vJoyAxisMaxValue}", false); vJoyObj.ResetVJD(vJoyID); vJoyAvailable = true; } } else { vJoyAvailable = false; AppLogger.LogToGui($"ERROR. VJoy device# {vJoyID} or {axis} axis not available. Check vJoy driver installation and configuration", false); } } catch { vJoyAvailable = false; AppLogger.LogToGui("ERROR. vJoy initialization failed. Make sure that DS4Windows application can find vJoyInterface.dll library file", false); } } }
private void Initialize_vJoy() { // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { MessageBox.Show("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); Program._shouldExit = true; System.Environment.Exit(0); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: break; case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: MessageBox.Show("vJoy Device is already owned by another feeder\nInput feeding will not occur."); //System.Environment.Exit(0); return; case VjdStat.VJD_STAT_MISS: MessageBox.Show("vJoy Device is not installed or disabled\nInput feeding will not occur."); //System.Environment.Exit(0); return; default: MessageBox.Show("vJoy Device general error\nInput feeding will not occur."); //System.Environment.Exit(0); return; } ; // Get the number of buttons and POV Hat switchessupported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { MessageBox.Show("Failed to acquire vJoy device number"); Program._shouldExit = true; System.Environment.Exit(0); } joystick.ResetVJD(id); }
public VJoyFeeder() { _joystick = new vJoy(); _joystickState = new vJoy.JoystickState(); _id = 1; _joystick.ResetVJD(_id); if (!_joystick.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", _joystick.GetvJoyManufacturerString(), _joystick.GetvJoyProductString(), _joystick.GetvJoySerialNumberString()); // Get the state of the requested device VjdStat status = _joystick.GetVJDStatus(_id); switch (status) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", _id); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free\n", _id); break; case VjdStat.VJD_STAT_BUSY: Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", _id); return; case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", _id); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", _id); return; } ; // Test if DLL matches the driver UInt32 dllVer = 0, drvVer = 0; bool match = _joystick.DriverMatch(ref dllVer, ref drvVer); if (match) { Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", dllVer); } else { Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", drvVer, dllVer); } _joystick.AcquireVJD(_id); }
/// <summary> /// Checking VJoy - copied from documentation /// </summary> /// <returns></returns> private bool CheckVJoy() { if (!_joystick.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return(false); } // Get the state of the requested device VjdStat status = _joystick.GetVJDStatus(_deviceId); switch (status) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", _deviceId); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free\n", _deviceId); break; case VjdStat.VJD_STAT_BUSY: Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", _deviceId); return(false); case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", _deviceId); return(false); default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", _deviceId); return(false); } // Test if DLL matches the driver UInt32 dllVer = 0, drvVer = 0; bool match = _joystick.DriverMatch(ref dllVer, ref drvVer); if (match) { Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", dllVer); } else { Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", drvVer, dllVer); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_deviceId)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", _deviceId); return(false); } Console.WriteLine("Acquired: vJoy device number {0}.\n", _deviceId); return(true); }
string Joystick(dynamic input) { id = (uint)input.pid; joystick = new vJoy(); iReport = new vJoy.JoystickState(); if (!joystick.vJoyEnabled()) { return("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); } if (started == 0) { status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_MISS: case VjdStat.VJD_STAT_BUSY: default: return("vJoy error\n" + status); } ; if (!joystick.AcquireVJD(id)) { return("Cannot acquire!"); } joystick.ResetVJD(id); } started = 1; bool btnStatus = false; uint btnId = 0; string teste = ""; foreach (dynamic btn in input.buttons) { foreach (dynamic btnP in btn.Value) { if (btnP.Key == "bid") { btnId = (uint)btnP.Value; } if (btnP.Key == "status") { btnStatus = (bool)btnP.Value; } } joystick.SetBtn(btnStatus, id, btnId); teste += " " + btnId + ":(" + btnStatus + ")"; } joystick.SetAxis(((int)input.axis.X), id, HID_USAGES.HID_USAGE_X); joystick.SetAxis(((int)input.axis.Y), id, HID_USAGES.HID_USAGE_Y); return("vJoy Enabled! " + id + teste); }
// TODO: extract private bool CheckVJoyState() { StringBuilder stringBuilder = new StringBuilder().AppendLine("vJoy Device ID: " + this._settings.DeviceID); bool canContinue = true; string message; if (!this._joy.vJoyEnabled()) { stringBuilder.AppendLine("vJoy is not enabled."); canContinue = false; } VjdStat status = this._joy.GetVJDStatus(this._settings.DeviceID); switch (status) { case VjdStat.VJD_STAT_OWN: message = "vJoy Device is already owned by this feeder."; break; case VjdStat.VJD_STAT_FREE: message = "vJoy Device is free."; break; case VjdStat.VJD_STAT_BUSY: message = "vJoy Device is already owned by another feeder."; canContinue = false; break; case VjdStat.VJD_STAT_MISS: message = "vJoy Device is not installed or disabled."; canContinue = false; break; default: message = "vJoy Device general error."; canContinue = false; break; } stringBuilder.AppendLine(message); if (canContinue) { stringBuilder.AppendLine("vJoy check OK."); } else { stringBuilder.AppendLine("Cannot continue."); } this._logger.Log(stringBuilder.ToString()); return(canContinue); }
public void check2() //check if virual joystick have write driver installed and compatible with versions of vjoy { UInt32 DllVer = 0, DrvVer = 0; bool match = joystick1.DriverMatch(ref DllVer, ref DrvVer); if (match) { Debug.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", DllVer); } else { Debug.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer); } VjdStat status = joystick1.GetVJDStatus(joyid); switch (status) { case VjdStat.VJD_STAT_OWN: Debug.WriteLine("vJoy Device {0} is already owned by this feeder\n", joyid); break; case VjdStat.VJD_STAT_FREE: Debug.WriteLine("vJoy Device {0} is free\n", joyid); break; case VjdStat.VJD_STAT_BUSY: Debug.WriteLine( "vJoy Device {0} is already owned by another feeder\nCannot continue\n", joyid); return; case VjdStat.VJD_STAT_MISS: Debug.WriteLine( "vJoy Device {0} is not installed or disabled\nCannot continue\n", joyid); return; default: Debug.WriteLine("vJoy Device {0} general error\nCannot continue\n", joyid); return; } ; int nBtn = joystick1.GetVJDButtonNumber(joyid); int nDPov = joystick1.GetVJDDiscPovNumber(joyid); int nCPov = joystick1.GetVJDContPovNumber(joyid); bool X_Exist = joystick1.GetVJDAxisExist(joyid, HID_USAGES.HID_USAGE_X); bool Y_Exist = joystick1.GetVJDAxisExist(joyid, HID_USAGES.HID_USAGE_Y); bool Z_Exist = joystick1.GetVJDAxisExist(joyid, HID_USAGES.HID_USAGE_Z); bool RX_Exist = joystick1.GetVJDAxisExist(joyid, HID_USAGES.HID_USAGE_RX); prt = String.Format("Device[{0}]: Buttons={1}; DiscPOVs:{2}; ContPOVs:{3}", joyid, nBtn, nDPov, nCPov); Debug.WriteLine(prt); }
public void Connect() { if (!this.Connected) { // ensure device is available VjdStat status = this.joystick.GetVJDStatus(this.ID); switch (status) { case VjdStat.VJD_STAT_OWN: logger.Warn("vJoy Device {0} is already owned by this feeder", this.ID); break; case VjdStat.VJD_STAT_FREE: logger.Info("vJoy Device {0} is free", this.ID); break; case VjdStat.VJD_STAT_BUSY: logger.Fatal("vJoy Device {0} is already owned by another feeder\nCannot continue", this.ID); return; case VjdStat.VJD_STAT_MISS: logger.Fatal("vJoy Device {0} is not installed or disabled\nCannot continue", this.ID); return; default: logger.Fatal("vJoy Device {0} general error\nCannot continue", this.ID); return; } ; this.loadCapabilities(); // now aquire the vJoy device if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(this.ID)))) { logger.Fatal("Failed to acquire vJoy device number {0}.", this.ID); return; } else { logger.Info("Acquired: vJoy device number {0}.", this.ID); } if (this.SupportedFFBEffects.Count > 0) { VirtualFFBPacketHandler.AddFFBHandler(this.ID, this.FFBDataReceivedHandler); // this.ffbPacketHandler = new VirtualFFBPacketHandler(this.joystick, this); // this.joystick.FfbRegisterGenCB(this.OnVirtualFFBDataReceived, null); } this.joystick.ResetVJD(this.ID); this.Connected = true; } }
public override void Acquire(string id) { // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { throw new VJoyException("vJoy driver not enabled: Failed Getting vJoy attributes."); } UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (!match) { throw new VJoyException(String.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", DrvVer, DllVer)); } if (!int.TryParse(id, out this.id)) { throw new VJoyException(String.Format("Invalid joystcik id {0}", id)); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus((uint)this.id); switch (status) { case VjdStat.VJD_STAT_OWN: //MessageBox.Show(String.Format("vJoy Device {0} is already owned by this feeder\n", id)); break; case VjdStat.VJD_STAT_FREE: //MessageBox.Show(String.Format("vJoy Device {0} is free\n", id)); break; case VjdStat.VJD_STAT_BUSY: throw new VJoyException(String.Format("vJoy Device {0} is already owned by another feeder\nCannot continue", id)); case VjdStat.VJD_STAT_MISS: throw new VJoyException(String.Format("vJoy Device {0} is not installed or disabled\nCannot continue", id)); default: throw new VJoyException(String.Format("vJoy Device {0} general error\nCannot continue", id)); } ; // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD((uint)this.id)))) { throw new VJoyException(String.Format("Failed to acquire vJoy device number {0}.", id)); } _reset(); }
public InputHandler() { player1 = new vJoy(); player2 = new vJoy(); ///// Write access to vJoy Device - Basic VjdStat status = player1.GetVJDStatus(1); // Acquire the target string prt; if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!player1.AcquireVJD(1)))) { prt = String.Format("Failed to acquire vJoy device number {0}.", 1); } else { prt = String.Format("Acquired: vJoy device number {0}.", 1); } MessageBox.Show(prt); status = player2.GetVJDStatus(2); // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!player2.AcquireVJD(2)))) { prt = String.Format("Failed to acquire vJoy device number {0}.", 2); } else { prt = String.Format("Acquired: vJoy device number {0}.", 2); } MessageBox.Show(prt); usersList = new Dictionary <string, uint>(); commands = new Dictionary <string, Delegate>(); commands["left"] = new Func <uint, vJoy, bool>(Left); commands["right"] = new Func <uint, vJoy, bool>(Right); commands["up"] = new Func <uint, vJoy, bool>(Up); commands["down"] = new Func <uint, vJoy, bool>(Down); commands["a"] = new Func <uint, vJoy, bool>(A); commands["b"] = new Func <uint, vJoy, bool>(B); commands["start"] = new Func <uint, vJoy, bool>(Start); commands["c1"] = commands["z"] = new Func <uint, vJoy, bool>(C1); commands["c2"] = new Func <uint, vJoy, bool>(C2); commands["c3"] = new Func <uint, vJoy, bool>(C3); commands["c4"] = new Func <uint, vJoy, bool>(C4); commands["rb"] = new Func <uint, vJoy, bool>(RB); commands["lb"] = new Func <uint, vJoy, bool>(LB); commands["none"] = new Func <uint, vJoy, bool>(None); }
public void aquire(uint id) { VjdStat status = joystick.GetVJDStatus(id); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { ; } else { ; } }
private void ConnectToVirtualJoystick() { joystick = new vJoy(); if (!joystick.vJoyEnabled()) throw new Exception("Unable to connect to virtual joystick"); VjdStat joystickStatus = joystick.GetVJDStatus(JoystickId); if (joystickStatus != VjdStat.VJD_STAT_FREE) throw new Exception("State of Joystick is not free"); if (!joystick.AcquireVJD(JoystickId)) throw new Exception("Unable to acquire joystick"); joystick.GetVJDAxisMax(JoystickId, HID_USAGES.HID_USAGE_X, ref maxValue); joystick.ResetVJD(JoystickId); inputMultiplyer = maxValue / (maxDirectionVectorValue * 2d); // Max direction value }
public Dictionary <string, string> GetInfo() // Just for testing { Dictionary <string, string> info = new Dictionary <string, string>(); if (Vjoy.vJoyEnabled()) { info["Vendor"] = Vjoy.GetvJoyManufacturerString(); info["Product"] = Vjoy.GetvJoyProductString(); info["Serial"] = Vjoy.GetvJoyVersion().ToString(); // Why are serial and version backwards?? info["Version"] = Vjoy.GetvJoySerialNumberString(); UInt32 DllVer = 0, DrvVer = 0; info["Driver Match"] = Vjoy.DriverMatch(ref DllVer, ref DrvVer).ToString(); info["Number of Buttons"] = Vjoy.GetVJDButtonNumber(_vJoyNumber).ToString(); uint id = 1; // First device is 1 (not 0) - there is also no way to check for the number of devices (at least that I can find). VjdStat status = Vjoy.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: info["Status"] = "vJoy Device " + _vJoyNumber + " is already owned by this feeder"; break; case VjdStat.VJD_STAT_FREE: info["Status"] = "vJoy Device " + _vJoyNumber + " is free"; break; case VjdStat.VJD_STAT_BUSY: info["Status"] = "vJoy Device " + _vJoyNumber + " is already owned by another feeder"; break; case VjdStat.VJD_STAT_MISS: info["Status"] = "vJoy Device " + _vJoyNumber + " is not installed or disabled"; break; default: info["Status"] = "vJoy Device " + _vJoyNumber + " general error"; break; } } else { info["Status"] = "vJoy driver not enabled: Failed Getting vJoy attributes"; } return(info); }
public static bool InitJoy() { joyStick = new vJoy(); VjdStat status = joyStick.GetVJDStatus(joyId); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joyStick.AcquireVJD(joyId)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", joyId); return(false); } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", joyId); joyStick.ResetVJD(joyId); return(true); } }
public static bool checkJoystick(ref vJoy joystick, uint id) { bool checker = false; if (joystick.vJoyEnabled()) { VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: JoystickLog(null, new Logging.LogEventArgs($"Port {id} is already owned by this feeder (OK).")); checker = true; break; case VjdStat.VJD_STAT_FREE: JoystickLog(null, new Logging.LogEventArgs($"Port {id} is detected (OK).")); checker = true; break; case VjdStat.VJD_STAT_BUSY: JoystickLog(null, new Logging.LogEventArgs( $"Port {id} is already owned by another feeder, cannot continue.")); checker = false; return(checker); case VjdStat.VJD_STAT_MISS: JoystickLog(null, new Logging.LogEventArgs($"Port {id} is not detected.")); checker = false; return(checker); default: JoystickLog(null, new Logging.LogEventArgs($"Port {id} general error, cannot continue.")); checker = false; return(checker); } //fix missing buttons, if the count is off. if (joystick.GetVJDButtonNumber(id) != 12) { SystemHelper.CreateJoystick(id); } } return(checker); }
public void Connect() { if (!this.Connected) { // ensure device is available VjdStat status = this.joystick.GetVJDStatus(this.ID); switch (status) { case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_BUSY: case VjdStat.VJD_STAT_MISS: default: throw new Exception(String.Format("vJoy Device {0} is missing or already in use!\n", this.ID)); } ; // check driver version against local DLL version uint DllVer = 0, DrvVer = 0; if (!this.joystick.DriverMatch(ref DllVer, ref DrvVer)) { throw new Exception(String.Format("Version of vJoy Driver ({0:X}) does not match vJoy DLL Version ({1:X})!\n", DrvVer, DllVer)); } this.loadCapabilities(); // now aquire the vJoy device if (!joystick.AcquireVJD(this.ID)) { throw new Exception(String.Format("Failed to acquire vJoy device number {0}!\n", this.ID)); } if (this.SupportedFFBEffects.Count > 0) { this.joystick.FfbRegisterGenCB(this.OnVirtualFFBDataReceived, null); } this.joystick.ResetVJD(this.ID); this.Connected = true; } }
public static string setup(vJoy joystick, uint id) { if (!joystick.vJoyEnabled()) { return("Not enabled"); } UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (!match) { return("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})"); } VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: return("vJoy Device " + id + " is already owned by another feeder\nCannot continue"); case VjdStat.VJD_STAT_MISS: return("vJoy Device " + id + " is not installed or disabled\nCannot continue"); default: return("vJoy Device " + id + " general error. Cannot continue"); } ; if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { return("Failed to acquire vJoy device number " + id); } joystick.ResetVJD(id); return(null); }
public static bool InitJoy(IFfbListener listener) { joyStick = new vJoy(); ffbListener = listener; VjdStat status = joyStick.GetVJDStatus(joyId); if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joyStick.AcquireVJD(joyId)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", joyId); return(false); } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", joyId); joyStick.ResetVJD(joyId); joyStick.FfbRegisterGenCB(OnFFBEvent, joyId); return(true); } }