public void GetEnabledDevices() { var joystick = new vDev(); log.Info("Get virtual devices able to be acquired..."); List <int> enabledDevs = new List <int>(); log.Info("Check drivers enabled: "); IsDriverEnabled(DevType.vJoy); bool owned = false; bool exist = false; bool free = false; // loop through possible vJoy devices for (int i = 1; i <= 16; i++) { joystick.isDevOwned((uint)i, DevType.vJoy, ref owned); joystick.isDevFree((uint)i, DevType.vJoy, ref free); joystick.isDevExist((uint)i, DevType.vJoy, ref exist); if (free || owned) { log.Info("Found vJoy device " + i.ToString()); enabledDevs.Add(i); } } EnabledDevices = enabledDevs; }
protected void AcquireDevice(uint id, DevType devType) { if (devType == DevType.vJoy && (id < 1 || id > 16) // vjoy || devType == DevType.vXbox && (id < 1 || id > 4)) // xbox { log.Debug("AcquireVJoyDevice: Device index " + id + " was invalid. Returning false."); throw new PocketStrafeOutputDeviceException("Unable to acquire device " + id + ". Invalid index."); } bool owned = false; bool free = false; bool exist = false; _Joystick.isDevOwned((uint)id, devType, ref owned); _Joystick.isDevFree((uint)id, devType, ref free); _Joystick.isDevExist((uint)id, devType, ref exist); //Test if DLL matches the driver short DllVer = 0, DrvVer = 0; DrvVer = _Joystick.GetvJoyVersion(); log.Info("vJoy version " + DrvVer.ToString()); // Acquire the target (sets hDev) _Joystick.AcquireDev(id, devType, ref this._HDev); if (owned || (free && _HDev == 0)) { log.Info(String.Format("Failed to acquire " + (devType == DevType.vXbox ? "xBox" : "vJoy") + " device number {0}.", id)); throw new PocketStrafeOutputDeviceException(String.Format("Failed to acquire " + (devType == DevType.vXbox ? "xBox" : "vJoy") + " device number {0}.", id)); } else { log.Info(String.Format("Acquired: " + (devType == DevType.vXbox ? "xBox" : "vJoy") + " device number {0}.", id)); } bool AxisX = false; _Joystick.isAxisExist(_HDev, 1, ref AxisX); bool AxisY = false; _Joystick.isAxisExist(_HDev, 2, ref AxisY); bool AxisZ = false; _Joystick.isAxisExist(_HDev, 3, ref AxisZ); bool AxisRX = false; _Joystick.isAxisExist(_HDev, 4, ref AxisRX); bool AxisRY = false; _Joystick.isAxisExist(_HDev, 5, ref AxisRY); bool AxisRZ = false; _Joystick.isAxisExist(_HDev, 6, ref AxisRZ); // Get the number of buttons and POV Hat switchessupported by this vJoy device uint nBtn = 0; _Joystick.GetDevButtonN(_HDev, ref nBtn); uint nHat = 0; _Joystick.GetDevHatN(_HDev, ref nHat); int DiscPovNumber = _Joystick.GetVJDDiscPovNumber(id); // Print results log.Info(String.Format("Device {0} capabilities:", id)); log.Info(String.Format(" Number of buttons\t\t{0}", nBtn)); log.Info(String.Format(" Number of Hats\t{0}", nHat)); log.Info(String.Format(" Number of Descrete POVs\t\t{0}", DiscPovNumber)); log.Info(String.Format(" Axis X\t\t{0}", AxisX ? "Yes" : "No")); log.Info(String.Format(" Axis Y\t\t{0}", AxisY ? "Yes" : "No")); log.Info(String.Format(" Axis Z\t\t{0}", AxisZ ? "Yes" : "No")); log.Info(String.Format(" Axis Rx\t\t{0}", AxisRX ? "Yes" : "No")); log.Info(String.Format(" Axis Ry\t\t{0}", AxisRY ? "Yes" : "No")); log.Info(String.Format(" Axis Rz\t\t{0}", AxisRZ ? "Yes" : "No")); if (devType == DevType.vXbox) { log.Info("Checking for valid vXbox controller"); log.Info(" Checking axes..."); if (AxisX && AxisY && AxisZ && AxisRX && AxisRY && AxisRZ) { log.Info(" All axes found."); } else { log.Info(" Required axes not found, returning false"); throw new PocketStrafeOutputDeviceException("Virtual XBox controller invalid. Incorrect axes."); } log.Info(" Checking buttons..."); if (nBtn >= 10) { log.Info(" All buttons found."); } else { log.Info(" Buttons not found, returning false"); throw new PocketStrafeOutputDeviceException("Virtual XBox controller invalid. Incorrect buttons."); } } log.Info("j acquired " + (devType == DevType.vJoy ? "vJoy" : "xBox") + " device " + id); this.Id = devType == DevType.vXbox ? id + 1000 : id; this.VDevAcquired = true; ResetState(); _Joystick.ResetAll(); }