public MainWindowViewModel() { _client = new ServiceClient(); _joystickState = new vJoy.JoystickState(); /* Before it we should check if service is available */ if ((JoyCapabilities = _client.ConnectJoystick()).JoyId != 0) { JoyVM = new JoyVM(); JoyVM.PropertyChanged += JoyVM_PropertyChanged; } }
public void InformNewWiimoteState(WiimoteLib.WiimoteState ws) { // make a report vJoy.JoystickState iReport = new vJoy.JoystickState(); // specify device iReport.bDevice = (byte)wrappedJoystickId; // now position data: iReport.AxisX = RescaleAxis(-ws.AccelState.Values.Y, Xmax); iReport.AxisY = RescaleAxis(ws.AccelState.Values.X, Ymax); iReport.AxisZ = RescaleAxis(ws.AccelState.Values.Z, Zmax); // now buttons iReport.Buttons = WiimoteToUint(ws); wrappedJoystick.UpdateVJD(wrappedJoystickId, ref iReport); }
//initializer public JoyControl() { joystick = new vJoy(); iReport = new vJoy.JoystickState(); if (!joystick.vJoyEnabled()) { sta="vJoy driver not enabled: Failed Getting vJoy attributes."; return; } else sta= "Vendor: " + joystick.GetvJoyManufacturerString() + "\nProduct :" + joystick.GetvJoyProductString() + "\nVersion Number:" + joystick.GetvJoySerialNumberString(); iReport.AxisXRot = 16500; iReport.AxisYRot = 16500; iReport.AxisZRot = 16500; iReport.AxisX = 16500; iReport.AxisY = 16500; iReport.AxisZ = 16500; if (!joystick.UpdateVJD(id, ref iReport)) { joystick.AcquireVJD(id); } }
static void Main(string[] args) { try { joystick = new vJoy(); iReport = new vJoy.JoystickState(); } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("vJoy error,please reinstall vjoy."); return; } if (!joystick.vJoyEnabled()) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } // 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.ForegroundColor = ConsoleColor.Red; Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id); return; case VjdStat.VJD_STAT_MISS: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id); return; default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id); return; }; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); bool AxisSL0 = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_SL0); bool AxisSL1 = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_SL1); // 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); // Print results Console.WriteLine("vJoy Device {0}", id); Console.WriteLine("Checking...Numner of buttons\t\t{0}\tPass", nButtons); Console.WriteLine("Checking...Numner of Continuous POVs\t{0}\tPass", ContPovNumber); Console.WriteLine("Checking...Numner of Descrete POVs\t{0}\tPass", DiscPovNumber); if (ContPovNumber > DiscPovNumber) isPovCon = true; Console.WriteLine("Checking...Axis X\t\t\t{0}\tPass", AxisX ? "Yes" : "No"); Console.WriteLine("Checking...Axis Y\t\t\t{0}\tPass", AxisX ? "Yes" : "No"); Console.WriteLine("Checking...Axis Z\t\t\t{0}\tPass", AxisX ? "Yes" : "No"); Console.WriteLine("Checking...Axis Rx\t\t\t{0}\tPass", AxisRX ? "Yes" : "No"); Console.WriteLine("Checking...Axis Ry\t\t\t{0}\tPass", AxisRY ? "Yes" : "No"); Console.WriteLine("Checking...Axis Rz\t\t\t{0}\tPass", AxisRZ ? "Yes" : "No"); Console.WriteLine("Checking...Axis SL0\t\t\t{0}\tPass", AxisSL0 ? "Yes" : "No"); Console.WriteLine("Checking...Axis SL1\t\t\t{0}\tPass", AxisSL1 ? "Yes" : "No"); // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) Console.WriteLine("Checking...Version of Driver Matches DLL Version ({0:X})\n", DllVer); else Console.WriteLine("Checking...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(id)))) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id); return; } else Console.WriteLine("Acquired: vJoy device number {0}.\n", id); joystick.ResetAll(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("System All Green.Now Start..."); Console.ForegroundColor = ConsoleColor.White; readConfig(); printHello(); joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref axisMaxval); UdpState axisUdpState = new UdpState(); axisUdpState.ipEndPoint = new IPEndPoint(IPAddress.Any, AxisPort); axisUdpState.udpClient = new UdpClient(AxisPort); axisUdpState.udpClient.BeginReceive(AxisUDPRecieved, axisUdpState); UdpState ctlUdpState = new UdpState(); ctlUdpState.ipEndPoint = new IPEndPoint(IPAddress.Any, CtlPort); ctlUdpState.udpClient = new UdpClient(CtlPort); ctlUdpState.udpClient.BeginReceive(CtlUDPRecieved, ctlUdpState); try { NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in nics) { if (adapter.OperationalStatus != OperationalStatus.Up) //filter unavaliable interface continue; if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet | adapter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211) { IPInterfaceProperties ip = adapter.GetIPProperties(); UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses; foreach (UnicastIPAddressInformation ipadd in ipCollection) { if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork) //判断是否为ipv4 Console.WriteLine(adapter.Name + " : " + ipadd.Address.ToString());//获取ip } } } } catch (System.Security.SecurityException) { Console.WriteLine("firewall banned application."); } catch (Exception e) { Console.WriteLine(e.ToString()); } while (true) Thread.Sleep(1000000); }
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 Initialize() { // 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()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } else 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(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; case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", deviceId); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", deviceId); return; }; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(deviceId, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(deviceId, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(deviceId, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(deviceId, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(deviceId, HID_USAGES.HID_USAGE_RZ); // Get the number of buttons and POV Hat switchessupported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(deviceId); int ContPovNumber = joystick.GetVJDContPovNumber(deviceId); int DiscPovNumber = joystick.GetVJDDiscPovNumber(deviceId); // Print results Console.WriteLine("\nvJoy Device {0} capabilities:\n", deviceId); Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons); Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber); Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber); Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); Console.WriteLine("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No"); // 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); System.Threading.Thread.Sleep(500); // 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; } else Console.WriteLine("Acquired: vJoy device number {0}.\n", deviceId); joystick.GetVJDAxisMax(deviceId, HID_USAGES.HID_USAGE_X, ref xMaxVal); joystick.GetVJDAxisMin(deviceId, HID_USAGES.HID_USAGE_X, ref xMinVal); joystick.GetVJDAxisMax(deviceId, HID_USAGES.HID_USAGE_Y, ref yMaxVal); joystick.GetVJDAxisMin(deviceId, HID_USAGES.HID_USAGE_Y, ref yMinVal); }
public static void Main(string[] args) { // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); // Device ID can only be in the range 1-16 if (args.Length>0 && !String.IsNullOrEmpty(args[0])) id = Convert.ToUInt32(args[0]); if (id <= 0 || id > 16) { Console.WriteLine("Illegal device ID {0}\nExit!",id); return; } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } else 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; }; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); //bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); //bool AxisRY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY); //bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); // 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); // Print results Console.WriteLine("\nvJoy Device {0} capabilities:\n", id); Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons); Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber); Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber); Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Y\t\t{0}\n", AxisY ? "Yes" : "No"); //Console.WriteLine("Axis RX\t\t{0}\n", AxisRX ? "Yes" : "No"); //Console.WriteLine("Axis RY\t\t{0}\n", AxisRY ? "Yes" : "No"); //Console.WriteLine("Axis RZ\t\t{0}\n", AxisRZ ? "Yes" : "No"); // 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(id)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id); return ; } else Console.WriteLine("Acquired: vJoy device number {0}.\n", id); Console.WriteLine("\npress enter to stat feeding"); //Console.ReadKey(true); uint count = 0; X = 20; Y = 30; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); #if ROBUST // Reset this device to default values joystick.ResetVJD(id); // Feed the device in endless loop while (true) { lock (_locker) { //Console.WriteLine("JOYSTICK X: " + X.ToString() + " Y: " + Y.ToString()); //Console.WriteLine("coefficient: " + coefficient.ToString()); // Set position of 4 axes res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X); res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y); //res = joystick.SetAxis(RY, id, HID_USAGES.HID_USAGE_RX); //res = joystick.SetAxis(RY, id, HID_USAGES.HID_USAGE_RY); //res = joystick.SetAxis(RZ, id, HID_USAGES.HID_USAGE_RZ); // Press/Release Buttons //res = joystick.SetBtn(true, id, count / 50); //res = joystick.SetBtn(false, id, 1 + count / 50); } //Console.WriteLine(X); //Console.WriteLine(Y); // If Continuous POV hat switches installed - make them go round // For high values - put the switches in neutral state /*if (ContPovNumber>0) { if ((count * 70) < 30000) { res = joystick.SetContPov(((int)count * 70), id, 1); //res = joystick.SetContPov(((int)count * 70) + 2000, id, 2); res = joystick.SetContPov(((int)count * 70) + 4000, id, 3); res = joystick.SetContPov(((int)count * 70) + 6000, id, 4); } else { res = joystick.SetContPov(-1, id, 1); res = joystick.SetContPov(-1, id, 2); res = joystick.SetContPov(-1, id, 3); res = joystick.SetContPov(-1, id, 4); }; };*/ // If Discrete POV hat switches installed - make them go round // From time to time - put the switches in neutral state /*if (DiscPovNumber>0) { if (count < 550) { joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1); joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2); joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3); joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4); } else { joystick.SetDiscPov(-1, id, 1); joystick.SetDiscPov(-1, id, 2); joystick.SetDiscPov(-1, id, 3); joystick.SetDiscPov(-1, id, 4); }; };*/ System.Threading.Thread.Sleep(20); if (X > maxval) X = 0; if (Y > maxval) Y = 0; //Z += 350; if (Z > maxval) Z = 0; //XR += 220; if (XR > maxval) XR = 0; //ZR += 200; if (ZR > maxval) ZR = 0; //count++; //if (count > 640) // count = 0; } // While (Robust) #endif // ROBUST /* #if EFFICIENT byte[] pov = new byte[4]; while (true) { iReport.bDevice = (byte)id; iReport.AxisX = X; iReport.AxisY = Y; iReport.AxisZ = Z; iReport.AxisZRot = ZR; iReport.AxisXRot = XR; // Set buttons one by one iReport.Buttons = (uint)(0x1 << (int)(count / 20)); if (ContPovNumber>0) { // Make Continuous POV Hat spin iReport.bHats = (count*70); iReport.bHatsEx1 = (count*70)+3000; iReport.bHatsEx2 = (count*70)+5000; iReport.bHatsEx3 = 15000 - (count*70); if ((count*70) > 36000) { iReport.bHats = 0xFFFFFFFF; // Neutral state iReport.bHatsEx1 = 0xFFFFFFFF; // Neutral state iReport.bHatsEx2 = 0xFFFFFFFF; // Neutral state iReport.bHatsEx3 = 0xFFFFFFFF; // Neutral state }; } else { // Make 5-position POV Hat spin pov[0] = (byte)(((count / 20) + 0)%4); pov[1] = (byte)(((count / 20) + 1) % 4); pov[2] = (byte)(((count / 20) + 2) % 4); pov[3] = (byte)(((count / 20) + 3) % 4); iReport.bHats = (uint)(pov[3]<<12) | (uint)(pov[2]<<8) | (uint)(pov[1]<<4) | (uint)pov[0]; if ((count) > 550) iReport.bHats = 0xFFFFFFFF; // Neutral state }; /*** 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)) { Console.WriteLine("Feeding vJoy device number {0} failed - try to enable device then press enter\n", id); Console.ReadKey(true); joystick.AcquireVJD(id); } System.Threading.Thread.Sleep(20); count++; if (count > 640) count = 0; X += 150; if (X > maxval) X = 0; Y += 250; if (Y > maxval) Y = 0; Z += 350; if (Z > maxval) Z = 0; XR += 220; if (XR > maxval) XR = 0; ZR += 200; if (ZR > maxval) ZR = 0; }; // While #endif // EFFICIENT*/ } // Main
public TesterForm() { InitializeComponent(); joystick = new vJoy(); position = new vJoy.JoystickState(); ///// General driver data short iVer = joystick.GetvJoyVersion(); bool enabled = joystick.vJoyEnabled(); string Prd = joystick.GetvJoyProductString(); string Mnf = joystick.GetvJoyManufacturerString(); string Srl = joystick.GetvJoySerialNumberString(); string prt = String.Format("Product: {0}; Version {1:X}; Manuf: {2}; Serial:{3}", Prd, iVer, Mnf, Srl); label1.Text = prt; Enbld.Checked = enabled; ///// vJoy Device properties int nBtn = joystick.GetVJDButtonNumber(id); int nDPov = joystick.GetVJDDiscPovNumber(id); int nCPov = joystick.GetVJDContPovNumber(id); bool X_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool Y_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool Z_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool RX_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); prt = String.Format("Device[{0}]: Buttons={1}; DiscPOVs:{2}; ContPOVs:{3}", id, nBtn, nDPov, nCPov); label2.Text = prt; UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) prt = String.Format("Version of Driver Matches DLL Version {0:X}", DllVer); else prt = String.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", DrvVer, DllVer); label7.Text = prt; long max = 10, min = 10; bool ok; ok = joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref max); ok = joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_X, ref min); ///// Write access to vJoy Device - Basic VjdStat status; status = joystick.GetVJDStatus(id); bool acq = joystick.AcquireVJD(id); status = joystick.GetVJDStatus(id); position.AxisX = 1000; position.AxisY = 5000; position.AxisZ = 10000; position.AxisXRot = 20000; position.Buttons = 0xA5A5A5A5; position.ButtonsEx1 = 0; bool upd = joystick.UpdateVJD(id, ref position); status = joystick.GetVJDStatus(id); //// Reset functions joystick.ResetButtons(id); // Register callback function // Function to register: Removal() // User data to pass: label2 joystick.RegisterRemovalCB(Removal, label2); }
public KeyBind(int index, string label, string type, string keyname, byte keycode) { Index = index; Label = label; Type = type; KeyName = keyname; KeyCode = keycode; if (type == "Joystick") { joystick = new vJoy(); joystickReport = new vJoy.JoystickState(); } }
bool FeedDinputDevice(uint id, out string message) { message = ""; // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); // Device ID can only be in the range 1-16 if (id <= 0 || id > 16) { message += string.Format("Illegal device ID {0}\nExit!", id); return false; } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { message += string.Format("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return false; } else message += string.Format("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: message += string.Format("vJoy Device {0} is already owned by this feeder\n", id); break; case VjdStat.VJD_STAT_FREE: message += string.Format("vJoy Device {0} is free\n", id); break; case VjdStat.VJD_STAT_BUSY: message += string.Format("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id); return false; case VjdStat.VJD_STAT_MISS: message += string.Format("vJoy Device {0} is not installed or disabled\nCannot continue\n", id); return false; default: message += string.Format("vJoy Device {0} general error\nCannot continue\n", id); return false; }; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); // Get the number of buttons and POV Hat switches supported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Print results message += string.Format("\nvJoy Device {0} capabilities:\n", id); message += string.Format("Number of buttons\t\t{0}\n", nButtons); message += string.Format("Number of Continuous POVs\t{0}\n", ContPovNumber); message += string.Format("Number of Discrete POVs\t\t{0}\n", DiscPovNumber); message += string.Format("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); message += string.Format("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No"); message += string.Format("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No"); message += string.Format("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); message += string.Format("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No"); // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { message += string.Format("Version of Driver Matches DLL Version ({0:X})\n", DllVer); } else { message += string.Format("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(id)))) { message += string.Format("Failed to acquire vJoy device number {0}.\n", id); return false; } else { message += string.Format("Acquired: vJoy device number {0}.\n", id); } int X, Y, Z, ZR, XR; uint count = 0; long maxval = 0; X = 20; Y = 30; Z = 40; XR = 60; ZR = 80; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); bool res; // Reset this device to default values joystick.ResetVJD(id); // Feed the device in endless loop while (!Program.IsClosing && FeedingEnabled) { // Set position of 4 axes res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X); res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y); res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z); res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX); res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ); // Press/Release Buttons res = joystick.SetBtn(true, id, count / 50); res = joystick.SetBtn(false, id, 1 + count / 50); // If Continuous POV hat switches installed - make them go round // For high values - put the switches in neutral state if (ContPovNumber > 0) { if ((count * 70) < 30000) { res = joystick.SetContPov(((int)count * 70), id, 1); res = joystick.SetContPov(((int)count * 70) + 2000, id, 2); res = joystick.SetContPov(((int)count * 70) + 4000, id, 3); res = joystick.SetContPov(((int)count * 70) + 6000, id, 4); } else { res = joystick.SetContPov(-1, id, 1); res = joystick.SetContPov(-1, id, 2); res = joystick.SetContPov(-1, id, 3); res = joystick.SetContPov(-1, id, 4); }; }; // If Discrete POV hat switches installed - make them go round // From time to time - put the switches in neutral state if (DiscPovNumber > 0) { if (count < 550) { joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1); joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2); joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3); joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4); } else { joystick.SetDiscPov(-1, id, 1); joystick.SetDiscPov(-1, id, 2); joystick.SetDiscPov(-1, id, 3); joystick.SetDiscPov(-1, id, 4); }; }; System.Threading.Thread.Sleep(20); X += 150; if (X > maxval) X = 0; Y += 250; if (Y > maxval) Y = 0; Z += 350; if (Z > maxval) Z = 0; XR += 220; if (XR > maxval) XR = 0; ZR += 200; if (ZR > maxval) ZR = 0; count++; if (count > 640) count = 0; } // While (Robust) return true; }
public MainForm() { // 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()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } else 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; }; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); // 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); // Print results Console.WriteLine("\nvJoy Device {0} capabilities:\n", id); Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons); Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber); Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber); Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); Console.WriteLine("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No"); // 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(id)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id); return; } else Console.WriteLine("Acquired: vJoy device number {0}.\n", id); // // Required for Windows Form Designer support // InitializeComponent(); controllerBox = 0; extendedView = false; //pictureBox1.Image = new Bitmap(String.Concat(path,"\\images\\/images/xboxControllerFront.png")); path = absPath(); //Background images pictureBox1.Image = new Bitmap(this.GetType(), "xboxControllerFront.png"); pictureBox2.Image = new Bitmap(this.GetType(), "xboxControllerTop.png"); //Marks mark = new Bitmap(this.GetType(), "green_mark.png"); markAxisL = new Bitmap(this.GetType(), "markAxis.png"); markAxisR = new Bitmap(this.GetType(), "markAxis.png"); markLB = new Bitmap(this.GetType(), "green_LB.png"); markRB = new Bitmap(this.GetType(), "green_RB.png"); markLT = new Bitmap(this.GetType(), "green_LT.png"); markRT = new Bitmap(this.GetType(), "green_RT.png"); //Extended triggers and bumpers markFLB = new Bitmap(this.GetType(), "green_FLB.png"); markFRB = new Bitmap(this.GetType(), "green_FRB.png"); markFLT = new Bitmap(this.GetType(), "green_FLT.png"); markFRT = new Bitmap(this.GetType(), "green_FRT.png"); pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); pictureBox2.Paint += new PaintEventHandler(pictureBox2_Paint); timer = new UITimer(); timer.Interval = 10; timer.Tick += new EventHandler(timer_Tick); timer.Start(); // Create the thread object. This does not start the thread. workerObject = new Worker(); workerThread = new Thread(workerObject.DoWork); // Start the worker thread. //workerThread.Start(); }
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); }