public void AcquireDevice(uint id) { bool res = vjoy.AcquireVJD(id); vjoy.ResetVJD(id); Console.WriteLine("Res: " + res); }
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"); } }
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(); }
private void ConnectClient() { try { VJoy = new vJoy(); if (!VJoy.vJoyEnabled()) { Connection.LogSDMessage("vJoy driver not enabled: Failed Getting vJoy attributes."); Logger.Instance.LogMessage(TracingLevel.ERROR, "vJoy driver not enabled: Failed Getting vJoy attributes."); } else { Connection.LogSDMessage($"Vendor: {VJoy.GetvJoyManufacturerString()}\nProduct :{VJoy.GetvJoyProductString()}\nVersion Number:{VJoy.GetvJoySerialNumberString()}\n"); Logger.Instance.LogMessage(TracingLevel.INFO, $"Vendor: {VJoy.GetvJoyManufacturerString()}\nProduct :{VJoy.GetvJoyProductString()}\nVersion Number:{VJoy.GetvJoySerialNumberString()}\n"); } if (!VJoy.AcquireVJD(JoystickId)) { Connection.ShowAlert().Start(); } else { VJoy.ResetAll(); } } catch (ArgumentException ex) { Connection.LogSDMessage($"{ex.Message}"); Logger.Instance.LogMessage(TracingLevel.ERROR, $"{ex.Message}"); } }
public IWriter Create(Identifier id) { var device = new vJoy(); device.AcquireVJD(id.Id); device.ResetVJD(id.Id); return(new Writer(id, device)); }
public void update() { if (!device.UpdateVJD(id, ref state)) { device.AcquireVJD(id); Thread.Sleep(1); update(); } }
public MainWindow() { InitializeComponent(); this.Leap_Controller = new Controller(); this.Leap_Listener = new LeapEventListener(this); Leap_Controller.AddListener(Leap_Listener); Leap_Controller.SetPolicyFlags(Controller.PolicyFlag.POLICYBACKGROUNDFRAMES); vJoy_Joystick = new vJoy(); if (!vJoy_Joystick.vJoyEnabled()) { return; } UInt32 DllVer = 0, DrvVer = 0; vJoy_Joystick.DriverMatch(ref DllVer, ref DrvVer); vJoy_Joystick.AcquireVJD(vJoy_id); vJoy_Joystick.ResetVJD(vJoy_id); Trig_En = new SolidColorBrush(Colors.LightGreen); Trig_Dis = Text_Trig_Max_Up.Background; try { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("LeapJoySets.bin", FileMode.Open, FileAccess.Read, FileShare.Read); Data_Set = (DataSet)formatter.Deserialize(stream); stream.Close(); } catch { Data_Set = new DataSet(); } Text_Max_Up.Text = Data_Set.Axis_Max_Up.ToString(); Text_Max_Pitch.Text = Data_Set.Axis_Max_Pitch.ToString(); Text_Max_Roll.Text = Data_Set.Axis_Max_Roll.ToString(); Text_Max_Yaw.Text = Data_Set.Axis_Max_Yaw.ToString(); Text_Min_Up.Text = Data_Set.Axis_Min_Up.ToString(); Text_Min_Pitch.Text = Data_Set.Axis_Min_Pitch.ToString(); Text_Min_Roll.Text = Data_Set.Axis_Min_Roll.ToString(); Text_Min_Yaw.Text = Data_Set.Axis_Min_Yaw.ToString(); Text_Trig_Max_Up.Text = Data_Set.Axis_Trig_Max_Up.ToString(); Text_Trig_Max_Pitch.Text = Data_Set.Axis_Trig_Max_Pitch.ToString(); Text_Trig_Max_Roll.Text = Data_Set.Axis_Trig_Max_Roll.ToString(); Text_Trig_Max_Yaw.Text = Data_Set.Axis_Trig_Max_Yaw.ToString(); Text_Trig_Min_Up.Text = Data_Set.Axis_Trig_Min_Up.ToString(); Text_Trig_Min_Pitch.Text = Data_Set.Axis_Trig_Min_Pitch.ToString(); Text_Trig_Min_Roll.Text = Data_Set.Axis_Trig_Min_Roll.ToString(); Text_Trig_Min_Yaw.Text = Data_Set.Axis_Trig_Min_Yaw.ToString(); rdy = true; }
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); }
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); }
static void Main(string[] args) { uint index = 1; var joystick = new vJoy(); if (!joystick.vJoyEnabled()) { throw new Exception("vJoy driver not enabled: Failed Getting vJoy attributes"); } var status = joystick.GetVJDStatus(index); string error = null; switch (status) { case VjdStat.VJD_STAT_BUSY: error = "vJoy Device {0} is already owned by another feeder"; break; case VjdStat.VJD_STAT_MISS: error = "vJoy Device {0} is not installed or disabled"; break; case VjdStat.VJD_STAT_UNKN: error = ("vJoy Device {0} general error"); break; } if (error == null && !joystick.AcquireVJD(index)) { error = "Failed to acquire vJoy device number {0}"; } if (error != null) { throw new Exception(string.Format(error, index)); } joystick.ResetVJD(index); if (!FfbStart(index)) { throw new Exception(string.Format("Failed to start Forcefeedback on device {0}", index)); } FfbRegisterGenCB(OnEffect, IntPtr.Zero); Console.ReadLine(); FfbStop(index); joystick.RelinquishVJD(index); }
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 InitDevice(uint ID) { if (!vJoyEnabled()) { return; } ReleaseDevice(); bDeviceAcquired = m_joystick.AcquireVJD(ID); m_vJoyID = ID; }
public bool Poll() { JoystickState state; if ((wheelDevice == null) || (handbrakeDevice == null)) { return(false); } try { // poll the joystick handbrakeDevice.Poll(); // update the joystick state field state = handbrakeDevice.GetCurrentState(); iReport.bDevice = (byte)id; iReport.AxisZ = (int)((double)state.X * axisScale); wheelDevice.Poll(); // update the joystick state field state = wheelDevice.GetCurrentState(); iReport.AxisX = (int)((double)state.X * axisScale); iReport.AxisY = (int)((double)state.Y * axisScale); iReport.AxisZRot = (int)((double)state.RotationZ * axisScale); // Set joystick buttons one by one bool[] buttons = state.Buttons; for (int i = 0; i < buttons.Length; i++) { if (buttons[i]) { iReport.Buttons |= (uint)1 << i; } } // joystick povs /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/ if (!joystick.UpdateVJD(id, ref iReport)) { MessageBox.Show("Feeding vJoy device failed - try to enable device then press OK", "Error"); joystick.AcquireVJD(id); } } catch (Exception) { ClearDevices(); //MessageBox.Show("Connection to Joystick/Throttle was lost. Was it unplugged or locked by another application?", "Error"); return(false); } return(true); }
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 }
/// <summary> /// Connect to a Joystick instance /// </summary> /// <param name="n">The joystick ID 1..16</param> /// <returns>True if successfull</returns> public bool Connect(int n) { if (Connected) { return(true); // already connected } try { if (!vJoy.isDllLoaded) { return(false); // ERROR exit DLL not loaded } if (n <= 0 || n > 16) { return(false); // ERROR exit invalid Joystick ID } m_jsId = (uint)n; m_joystick = new vJoy( ); if (!m_joystick.vJoyEnabled( )) { Disconnect( ); // cleanup return(false); // ERROR exit } // try to control.. Connected = m_joystick.isVJDExists(m_jsId); // exists? if (Connected) { Connected = m_joystick.AcquireVJD(m_jsId); // to use? } if (Connected) { bool r = m_joystick.ResetVJD(m_jsId); m_vJoystick = new vJoystick(m_joystick, m_jsId); // the one to use.. } else { m_jsId = 0; m_joystick = null; return(false); // ERROR exit } } catch { // wrong ... m_jsId = 0; m_joystick = null; } return(Connected); }
private void vJoyBox_CheckedChanged(object sender, EventArgs e) { if (currentHandle != new IntPtr(0)) { if (!keyboards[currentHandle].vJoyEnabled) { bool acquiredDevice = false; for (uint i = 1; i <= 16; i++) { if (virtualJoy.GetVJDStatus(i) == VjdStat.VJD_STAT_FREE) { virtualJoy.AcquireVJD(i); keyboards[currentHandle].vJoyEnabled = true; keyboards[currentHandle].vJoyId = i; acquiredDevice = true; virtualJoy.SetAxis(16384, keyboards[currentHandle].vJoyId, HID_USAGES.HID_USAGE_X); virtualJoy.SetAxis(16384, keyboards[currentHandle].vJoyId, HID_USAGES.HID_USAGE_Y); virtualJoy.SetAxis(16384, keyboards[currentHandle].vJoyId, HID_USAGES.HID_USAGE_RX); virtualJoy.SetAxis(16384, keyboards[currentHandle].vJoyId, HID_USAGES.HID_USAGE_RY); virtualJoy.SetAxis(1, keyboards[currentHandle].vJoyId, HID_USAGES.HID_USAGE_Z); MessageBox.Show($"Acquired vJoy device {i}."); break; } } if (!acquiredDevice) { MessageBox.Show("vJoy device acquisition failed: There are no free devices."); vJoyBox.CheckedChanged -= vJoyBox_CheckedChanged; vJoyBox.Checked = false; vJoyBox.CheckedChanged += vJoyBox_CheckedChanged; } } else { virtualJoy.RelinquishVJD(keyboards[currentHandle].vJoyId); MessageBox.Show($"Relinquished vJoy device {keyboards[currentHandle].vJoyId}."); keyboards[currentHandle].vJoyId = 17; keyboards[currentHandle].vJoyEnabled = false; } } else { MessageBox.Show("You have to select a Keyboard by clicking \"Detect Keyboard\" and pressing any key on the desired keyboard before changing settings."); vJoyBox.CheckedChanged -= vJoyBox_CheckedChanged; vJoyBox.Checked = false; vJoyBox.CheckedChanged += vJoyBox_CheckedChanged; } }
public void Start() { idVJoy = 1u; joystick = new vJoy(); var enabled = joystick.vJoyEnabled(); if (!enabled) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes."); return; } var vjdStatus = joystick.GetVJDStatus(idVJoy); Console.WriteLine(vjdStatus.ToString()); switch (vjdStatus) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", idVJoy); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free\n", idVJoy); break; case VjdStat.VJD_STAT_BUSY: Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", idVJoy); return; case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", idVJoy); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", idVJoy); return; } acquired = joystick.AcquireVJD(idVJoy); if (!acquired) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", idVJoy); return; } Console.WriteLine("Acquired: vJoy device number {0}.\n", idVJoy); }
public VJoyHandler(BongoManager manager, BongoInputMapping mapping, int id, int mic) : base(manager, mapping) { joystick = new vJoy(); uint _id = (uint)id; micSensitivity = mic; if (id <= 0 | id > 16) { Program.WriteErrorToConsoleAndExit("Invalid vJoy id"); } if (!joystick.vJoyEnabled()) { Program.WriteErrorToConsoleAndExit("vJoy not enabled"); } if (!joystick.AcquireVJD(_id)) { Program.WriteErrorToConsoleAndExit("Failed to acquire vJoy device"); } TranslateMapping(mapping); joystick.ResetVJD(_id); manager.TopRightPressed += () => joystick.SetBtn(true, _id, topRight); manager.BotRightPressed += () => joystick.SetBtn(true, _id, botRight); manager.TopLeftPressed += () => joystick.SetBtn(true, _id, topLeft); manager.BotLeftPressed += () => joystick.SetBtn(true, _id, botLeft); manager.StartPressed += () => joystick.SetBtn(true, _id, start); manager.TopRightReleased += () => joystick.SetBtn(false, _id, topRight); manager.BotRightReleased += () => joystick.SetBtn(false, _id, botRight); manager.TopLeftReleased += () => joystick.SetBtn(false, _id, topLeft); manager.BotLeftReleased += () => joystick.SetBtn(false, _id, botLeft); manager.StartReleased += () => joystick.SetBtn(false, _id, start); if (micButton == 255) { manager.MicUpdate += (int update) => joystick.SetAxis(update * micSensitivity, _id, micAxis); } else { manager.MicStarted += () => joystick.SetBtn(true, _id, micButton); manager.MicReleased += () => joystick.SetBtn(false, _id, micButton); } }
public static void EnablevJoy() { Console.WriteLine("Getting vJoy controller..."); joystick = new vJoy(); if (joystick.vJoyEnabled()) { Console.WriteLine("vJoy enabled!"); Console.WriteLine("vJoy ver: " + joystick.GetvJoyVersion()); Console.WriteLine("Manufacturer: " + joystick.GetvJoyManufacturerString()); Console.WriteLine("Product: " + joystick.GetvJoyProductString()); Console.WriteLine("Serial No. : " + joystick.GetvJoySerialNumberString()); Console.WriteLine("Searching for available joystick..."); for (uint i = 1; i < 16; i++) { Console.WriteLine($"Trying joystick {i}..."); var status = joystick.GetVJDStatus(i); Console.WriteLine($"Joystick status: {status}"); if (new VjdStat[] { VjdStat.VJD_STAT_OWN, VjdStat.VJD_STAT_FREE }.Contains(status))// is it owned already or ready to own? { vjd = i; break; } } if (vjd != 0) // joystick id can never be 0, not using -1 to avoid casting { Console.WriteLine("Attempting to acquire joystick..."); if (joystick.AcquireVJD(vjd)) { Console.WriteLine("Success!"); } else { Console.WriteLine("Failed to acquire joystick!"); } } else { Console.WriteLine("No joysticks available!"); } } else { Console.WriteLine("vJoy not enabled!"); } }
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 vJoyHelper(USBHelper usb) { _joystick = new vJoy(); bool tmp = _joystick.vJoyEnabled(); _jState = new vJoy.JoystickState(); _joystick.AcquireVJD(1); _joystick.ResetVJD(1); _maxVal = 0; _axisAry = new Dictionary <HID_USAGES, bool>(); foreach (HID_USAGES hidUsage in Enum.GetValues(typeof(HID_USAGES))) { _axisAry.Add(hidUsage, _joystick.GetVJDAxisExist(1, hidUsage)); } _joystick.GetVJDAxisMax(1, HID_USAGES.HID_USAGE_X, ref _maxVal); _usb = usb; usb.Polled += new EventHandler(OnUSBPolled); }
public void acquire() { ///acquire virtual joystick of id 'joyid' for manipulating VjdStat status; status = joystick1.GetVJDStatus(joyid); ///checking the status // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick1.AcquireVJD(joyid)))) { prt = String.Format("Failed to acquire vJoy device number {0}.", joyid); } else { prt = String.Format("Acquired: vJoy device number {0}.", joyid); } Debug.WriteLine(prt); }
/*void checkvJoyDeviceInputs() { * uint vjid = (uint)joyIDSelector.Value; * * setMLDataAsync(0, maplistsub.Available, joy.GetVJDAxisExist(vjid, HID_USAGES.HID_USAGE_X) ? "Yes" : "No"); * setMLDataAsync(1, maplistsub.Available, joy.GetVJDAxisExist(vjid, HID_USAGES.HID_USAGE_Y) ? "Yes" : "No"); * setMLDataAsync(2, maplistsub.Available, joy.GetVJDAxisExist(vjid, HID_USAGES.HID_USAGE_Z) ? "Yes" : "No"); * setMLDataAsync(3, maplistsub.Available, joy.GetVJDAxisExist(vjid, HID_USAGES.HID_USAGE_RX) ? "Yes" : "No"); * setMLDataAsync(4, maplistsub.Available, joy.GetVJDAxisExist(vjid, HID_USAGES.HID_USAGE_RY) ? "Yes" : "No"); * setMLDataAsync(5, maplistsub.Available, joy.GetVJDAxisExist(vjid, HID_USAGES.HID_USAGE_RZ) ? "Yes" : "No"); * setMLDataAsync(6, maplistsub.Available, joy.GetVJDAxisExist(vjid, HID_USAGES.HID_USAGE_SL0) ? "Yes" : "No"); * setMLDataAsync(7, maplistsub.Available, joy.GetVJDAxisExist(vjid, HID_USAGES.HID_USAGE_SL1) ? "Yes" : "No"); * }*/ void vJoyToggle() { if (checkStat(stat.VJDevReady) & !checkStat(stat.VJDevAttached)) { if (joy.AcquireVJD((uint)joyIDSelector.Value)) { setStat(stat.VJDevAttached); joyIDSelector.Enabled = false; btnJoyAttach.Text = "Detach"; } } else { joy.RelinquishVJD((uint)joyIDSelector.Value); setStat(stat.VJDevAttached, 0); joyIDSelector.Enabled = true; btnJoyAttach.Text = "Attach"; } refreshStatusIcons(stat.VJOK); }
void Start() { joystick = new vJoy(); iReport = new vJoy.JoystickState(); if (joystick.vJoyEnabled()) { VjdStat status = joystick.GetVJDStatus(1); bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); joystick.AcquireVJD(id); joystick.ResetVJD(id); } fpsMonitor = GetComponent <FpsMonitor> (); displayFacePointsToggle.isOn = displayFacePoints; displayAxesToggle.isOn = displayAxes; displayHeadToggle.isOn = displayHead; displayEffectsToggle.isOn = displayEffects; enableLowPassFilterToggle.isOn = enableLowPassFilter; webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper> (); dlibShapePredictorFileName = DlibFaceLandmarkDetectorExample.dlibShapePredictorFileName; #if UNITY_WEBGL && !UNITY_EDITOR getFilePath_Coroutine = DlibFaceLandmarkDetector.UnityUtils.Utils.getFilePathAsync(dlibShapePredictorFileName, (result) => { getFilePath_Coroutine = null; dlibShapePredictorFilePath = result; Run(); }); StartCoroutine(getFilePath_Coroutine); #else dlibShapePredictorFilePath = DlibFaceLandmarkDetector.UnityUtils.Utils.getFilePath(dlibShapePredictorFileName); Run(); #endif }
public static void Feed(vJoy vjoy, Configuration config, EDStatusMonitor monitor) { // copy configuration and status to prevent changes from taking effect during the feed process uint deviceId = (uint)config.DeviceId; Dictionary <string, int> buttonIds = config.ButtonConfigurationCopy; Dictionary <string, bool> statusFlags = monitor.StatusCopy; if (!vjoy.AcquireVJD(deviceId)) { throw new ButtonFeederException($"vJoy error: Unable to acquire vJoy device #{deviceId}"); } foreach (string flag in statusFlags.Keys) { bool status = statusFlags[flag]; char buttonId = (char)buttonIds[flag]; vjoy.SetBtn(status, deviceId, buttonId); } vjoy.RelinquishVJD(deviceId); }
private static bool InitVJoyById(vJoy vJoy, uint id) { // Get the state of the requested device VjdStat status = vJoy.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: Console.Error.WriteLine("vJoy {0} busy", id); return(false); case VjdStat.VJD_STAT_MISS: Console.Error.WriteLine("vJoy {0} missing", id); return(false); default: Console.Error.WriteLine("vJoy {0} error {1}", id, status); return(false); } // Acquire joystick if (!vJoy.AcquireVJD(id)) { Console.Error.WriteLine("Failed to acquire vJoy {0}", id); return(false); } else { Console.WriteLine("Acquired: vJoy {0}", id); } // Reset this joy vJoy.ResetVJD(id); return(true); }
internal static void UpdateState() { if (Verbose) { Loger.InfoContinue($"Axe1X {SerialStates.Axes[0]} Axe1Y {SerialStates.Axes[1]} Axe2X {SerialStates.Axes[2]} Axe2y {SerialStates.Axes[3]}"); } iReport.bDevice = (byte)id; iReport.AxisX = SerialStates.ConverAxeValue(0); iReport.AxisY = SerialStates.ConverAxeValue(1); iReport.AxisXRot = SerialStates.ConverAxeValue(2); iReport.AxisYRot = SerialStates.ConverAxeValue(3); iReport.bHats = SerialStates.HatStates; iReport.Buttons = 0; if (!(SerialStates.Buttons[0] && SerialStates.Buttons[1])) { for (int i = 0; i < SerialStates.Buttons.Length; i++) { if (SerialStates.Buttons[i]) { iReport.Buttons = iReport.Buttons | ((uint)0b1 << i); } } } if (!joystick.UpdateVJD(id, ref iReport)) { Loger.Error($"Feeding vJoy device number {id} failed - wait 1s"); Thread.Sleep(1000); joystick.AcquireVJD(id); } }
/** * Aquire or verify a vJoy device is already aquired */ private bool AcquireDevice(uint deviceId, VjdStat deviceStatus) { if (deviceStatus == VjdStat.VJD_STAT_FREE) { if (vjoy.AcquireVJD(deviceId)) { Debug.LogFormat("Aquired vJoy device {0}", deviceId); } else { Debug.LogErrorFormat("Unable to aquire vJoy device {0}", deviceId); SetStatus(VJoyStatus.DeviceNotAquired); return(false); } } else if (deviceStatus == VjdStat.VJD_STAT_OWN) { Debug.LogFormat("vJoy device {0} already aquired", deviceId); } return(true); }
public bool Poll() { if (!AllDevicesReady()) { return(false); } if (!vjoyEnabled) { vjoyEnabled = joystick.AcquireVJD(id); if (!vjoyEnabled) { return(false); } } try { iReport.bDevice = (byte)id; iReport.Buttons = 0; iReport.bHats = iReport.bHatsEx1 = iReport.bHatsEx2 = iReport.bHatsEx3 = uint.MaxValue; Feed(); /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/ if (!joystick.UpdateVJD(id, ref iReport)) { vjoyEnabled = false; mainForm.ReportVJoyDisconnect(); } } catch (System.Exception) { ClearDevices(); return(false); } return(true); }