public void ResetDeviceAxes(uint deviceID) { foreach (var axis in Enum.GetValues(typeof(HID_USAGES))) { joystick.SetAxis(0x4000, deviceID, (HID_USAGES)axis); } }
private void setAxis(List <State> states) { Position directionX = Position.NULL, directionY = Position.NULL; //0=up, 1=down, 2=right, 3=left if (states[0] == State.KeyDown || states[0] == State.KeyHold) { directionX = Position.POSITIVE; } else if (states[1] == State.KeyDown || states[1] == State.KeyHold) { directionX = Position.NEGATIVE; } if (states[2] == State.KeyDown || states[2] == State.KeyHold) { directionY = Position.POSITIVE; } else if (states[3] == State.KeyDown || states[3] == State.KeyHold) { directionY = Position.NEGATIVE; } axisX = calculateAxisPosition(axisX, directionX); axisY = calculateAxisPosition(axisY, directionY); joystick.SetAxis((int)axisX, jID, HID_USAGES.HID_USAGE_X); joystick.SetAxis((int)axisY, jID, HID_USAGES.HID_USAGE_Y); }
public void SetNewPosition(float newPositionX, float newPositionY) { int xPosition = (int)((newPositionX + maxDirectionVectorValue) * inputMultiplyer); int yPosition = (int)((newPositionY + maxDirectionVectorValue) * inputMultiplyer); joystick.SetAxis(xPosition, JoystickId, HID_USAGES.HID_USAGE_X); joystick.SetAxis(yPosition, JoystickId, HID_USAGES.HID_USAGE_Y); }
public void Throttle(float value) { if (acquired) { var axisVal = (int)Math.Round(value * 16384) + 16383; //# myLog("SetAxis " + str(axisVal)); joystick.SetAxis(axisVal, idVJoy, HID_USAGES.HID_USAGE_X); } }
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); }
public void SetAxis(int key, int value) { value = value * 32768 / 256; switch (key) { case 1: joystick.SetAxis(value, (uint)id, HID_USAGES.HID_USAGE_X); break; case 2: joystick.SetAxis(value, (uint)id, HID_USAGES.HID_USAGE_Y); break; case 3: joystick.SetAxis(value, (uint)id, HID_USAGES.HID_USAGE_Z); break; } }
private void setAxes() { // Set position of 4 axes X = (int)((double)maxval * cPitch); Y = (int)((double)maxval * cRoll); Z = (int)((double)maxval * cThr); XR = (int)((double)maxval * cYaw); ZR = (int)((double)maxval * cConv); 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); }
public void SetAxis(HID_USAGES Axis, int Value) { if (bDeviceAcquired) { m_joystick.SetAxis(Value, m_vJoyID, Axis); } }
public void Write(State state) { state.Axis.ToList().ForEach(x => { _device.SetAxis(Transform(x.Value), _id.Id, _axisToVjoy[x.Key]); }); }
public void SetAxis(int value, HID_USAGES axis) { if (!initialized) { return; } joystick.SetAxis(value, id, axis); }
private void HandleMouseMove(object sender, MouseEventArgs e) { var bounds = Screen.PrimaryScreen.Bounds; var minX = bounds.Left; var maxX = this._autoSize ? bounds.Right : (bounds.Left + this._manualWidth); var minY = bounds.Top; var maxY = this._autoSize ? bounds.Bottom : (bounds.Top + this._manualHeight); var deltaX = e.X - this._lastX; var deltaY = e.Y - this._lastY; this._lastX = this._autoCenter ? Clamp <int>(minX, e.X, maxX) : (minX + (maxX - minX) / 2); this._lastY = this._autoCenter ? Clamp <int>(minY, e.Y, maxY) : (minY + (maxY - minY) / 2); int xOut, yOut; if (this._autoCenter) { xOut = Clamp <int>(Convert.ToInt32(_axisMin), (int)Math.Round(_axisMid + _invertX * (deltaX * (deltaX * -1.0 / 1.1 + 500))), Convert.ToInt32(_axisMax)); yOut = Clamp <int>(Convert.ToInt32(_axisMin), (int)Math.Round(_axisMid + _invertY * (deltaY * (deltaY * -1.0 / 1.1 + 500))), Convert.ToInt32(_axisMax)); } else { var maxDeltaX = this._autoSize ? bounds.Width : this._manualWidth; var maxDeltaY = this._autoSize ? bounds.Height : this._manualHeight; var outputPerDeltaX = (_axisMax - _axisMin) / maxDeltaX; var outputPerDeltaY = (_axisMax - _axisMin) / maxDeltaY; xOut = Clamp <int>(Convert.ToInt32(_axisMin), (int)(_axisMid + _invertX * (deltaX + _senseX) * outputPerDeltaX), Convert.ToInt32(_axisMax)); yOut = Clamp <int>(Convert.ToInt32(_axisMin), (int)(_axisMid + _invertY * (deltaY + _senseY) * outputPerDeltaY), Convert.ToInt32(_axisMax)); } if (_leftJoy) { _joystick.SetAxis(xOut, this._id, HID_USAGES.HID_USAGE_X); _joystick.SetAxis(yOut, this._id, HID_USAGES.HID_USAGE_Y); } else { _joystick.SetAxis(xOut, this._id, HID_USAGES.HID_USAGE_RX); _joystick.SetAxis(yOut, this._id, HID_USAGES.HID_USAGE_RY); } }
public void SetAxis(int x, HID_USAGES usage) { if (!enabledAxis[usage]) { throw new Exception(string.Format("Axis {0} not enabled, enable it from VJoy config", usage)); } joystick.SetAxis(x + AxisMax, Index, usage); currentAxisValue[usage] = x; }
public void SetAxis(int x, HID_USAGES usage) { if (!enabledAxis[usage]) { return; } //throw new Exception(string.Format("Axis {0} not enabled, enable it from VJoy config", usage)); x += AxisMax; if (!modeDiffered) { _joystick.SetAxis(x, Index, usage); } else { switch (usage) { case HID_USAGES.HID_USAGE_X: report.AxisX = x; break; case HID_USAGES.HID_USAGE_Y: report.AxisY = x; break; case HID_USAGES.HID_USAGE_Z: report.AxisZ = x; break; case HID_USAGES.HID_USAGE_RX: report.AxisXRot = x; break; case HID_USAGES.HID_USAGE_RY: report.AxisYRot = x; break; case HID_USAGES.HID_USAGE_RZ: report.AxisZRot = x; break; case HID_USAGES.HID_USAGE_SL0: report.Slider = x; break; case HID_USAGES.HID_USAGE_SL1: report.Dial = x; break; default: throw new Exception($"Axis {usage} not tested"); } } currentAxisValue[usage] = x - AxisMax; }
public override void HandleControl(string line, vJoy joystick, uint deviceId) { if (line == string.Format("{0}\r", PushMsg)) { pos += 654; if (pos > 32767) { pos = 32767; } joystick.SetAxis(pos, deviceId, (HID_USAGES)Axis); } if (line == string.Format("{0}\r", ReleaseMsg)) { pos -= 654; if (pos < 1) { pos = 1; } joystick.SetAxis(pos, deviceId, (HID_USAGES)Axis); } }
/// <summary> /// アナログスティックの移動 /// </summary> /// <param name="n">0:アナログスティック(左) 1:アナログスティック(右)</param> /// <param name="x">上下</param> /// <param name="y">左右</param> public void MoveStick(uint n, long x, long y) { HID_USAGES usageX = HID_USAGES.HID_USAGE_X; HID_USAGES usageY = HID_USAGES.HID_USAGE_Y; switch (n) { case 0: usageX = HID_USAGES.HID_USAGE_X; usageY = HID_USAGES.HID_USAGE_Y; break; case 1: usageX = HID_USAGES.HID_USAGE_Z; usageY = HID_USAGES.HID_USAGE_RZ; break; } x = 100 - x; y = 100 - y; joystick.SetAxis((int)(m_nAxisMax * x) / 100, rID, usageX); joystick.SetAxis((int)(m_nAxisMax * y) / 100, rID, usageY); }
private void HandleMouseMove(object sender, MouseEventArgs e) { var bounds = Screen.PrimaryScreen.Bounds; var minX = bounds.Left; var maxX = this.autoSize ? bounds.Right : (bounds.Left + this.manualWidth); var minY = bounds.Top; var maxY = this.autoSize ? bounds.Bottom : (bounds.Top + this.manualHeight); int deltaX = e.X - this.lastX; int deltaY = e.Y - this.lastY; this.lastX = this.autoCenter ? Clamp <int>(minX, e.X, maxX) : (minX + (maxX - minX) / 2); this.lastY = this.autoCenter ? Clamp <int>(minY, e.Y, maxY) : (minY + (maxY - minY) / 2); int xOut, yOut; if (this.autoCenter) { xOut = Clamp <int>(Convert.ToInt32(AXIS_MIN), (int)Math.Round(AXIS_MID + invertX * (deltaX * (deltaX * -1.0 / 1.1 + 500))), Convert.ToInt32(AXIS_MAX)); yOut = Clamp <int>(Convert.ToInt32(AXIS_MIN), (int)Math.Round(AXIS_MID + invertY * (deltaY * (deltaY * -1.0 / 1.1 + 500))), Convert.ToInt32(AXIS_MAX)); } else { int maxDeltaX = this.autoSize ? bounds.Width : this.manualWidth; int maxDeltaY = this.autoSize ? bounds.Height : this.manualHeight; long outputPerDeltaX = (AXIS_MAX - AXIS_MIN) / maxDeltaX; long outputPerDeltaY = (AXIS_MAX - AXIS_MIN) / maxDeltaY; xOut = Clamp <int>(Convert.ToInt32(AXIS_MIN), (int)(AXIS_MID + invertX * deltaX * outputPerDeltaX), Convert.ToInt32(AXIS_MAX)); yOut = Clamp <int>(Convert.ToInt32(AXIS_MIN), (int)(AXIS_MID + invertY * deltaY * outputPerDeltaY), Convert.ToInt32(AXIS_MAX)); } //Console.WriteLine(String.Format("{0}, {1} -> {2}, {3}", lastX, lastY, xOut, yOut)); joystick.SetAxis(xOut, this.id, HID_USAGES.HID_USAGE_X); joystick.SetAxis(yOut, this.id, HID_USAGES.HID_USAGE_Y); }
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 void SetButtonState(uint id, string button, int value) { if (button.Contains("Buttons")) { vjoy.SetBtn(value > 0, id, (uint)RLocalInput.MapButtonToId[button] + 1); } else if (button.Contains("PointOfViewControllers")) { vjoy.SetContPov(value, id, 1); } else { var axis = MapButtonToAxis[button]; vjoy.SetAxis(value / 2, id, axis); } }
internal void MoveAxisBy(int movement) { if (_joystick != null) { _axisPosition += movement; if (_axisPosition > _maxAxisValue) { _axisPosition = (int)_maxAxisValue; } else if (_axisPosition < 0) { _axisPosition = 0; } _joystick.SetAxis(_axisPosition, _vJoyId, (HID_USAGES)_vJoyAxisNumber); Debug.WriteLine("Moving vJoy {0} Axis {1} to {2}", _vJoyId, (HID_USAGES)_vJoyAxisNumber, _axisPosition); } }
IEnumerator Simulation() { controller.SetPolicy(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES); controller.SetPolicyFlags(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES); controller.AddListener(listener); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); //uint count = 0; long maxval = 0; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); AxisMax = (int)maxval; AxisZero = AxisMax / 2; int AxisX = AxisZero; int AxisY = AxisZero; int AxisZ = AxisZero; int AxisZR = AxisZero; int AxisXR = AxisZero; AxisReset(); Vector3 OldPosition = Tool.transform.localPosition; while (true) { Vector3 pos = Tool.transform.localPosition; if (Mathf.Abs(OldPosition.sqrMagnitude - pos.sqrMagnitude) > 0.0001f) { AxisX = pos.x > 0 ? AxisPositive(pos.x, JoyConfig.Config.MaxPosition.x, JoyConfig.Config.Deadband.x) : AxisNegative(pos.x, JoyConfig.Config.MinPosition.x, -JoyConfig.Config.Deadband.x); AxisZ = pos.y > 0 ? AxisPositive(pos.y, JoyConfig.Config.MaxPosition.y, JoyConfig.Config.Deadband.y) : AxisNegative(pos.y, JoyConfig.Config.MinPosition.y, -JoyConfig.Config.Deadband.y); AxisY = pos.z > 0 ? AxisPositive(pos.z, JoyConfig.Config.MaxPosition.z, JoyConfig.Config.Deadband.z) : AxisNegative(pos.z, JoyConfig.Config.MinPosition.z, -JoyConfig.Config.Deadband.z); joystick.SetAxis(AxisX, id, HID_USAGES.HID_USAGE_X); joystick.SetAxis(AxisY, id, HID_USAGES.HID_USAGE_Y); joystick.SetAxis(AxisZ, id, HID_USAGES.HID_USAGE_Z); OldPosition = Tool.transform.localPosition; } ScreenLog.JLog.LinkString("AxisX = " + (float)AxisX / AxisMax); ScreenLog.JLog.LinkString("AxisY = " + (float)AxisY / AxisMax); ScreenLog.JLog.LinkString("AxisZ = " + (float)AxisZ / AxisMax); yield return(new WaitForFixedUpdate()); } }
// this code runs when a message was received void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { string ReceivedMessage = Encoding.UTF8.GetString(e.Message); writeMessage(e.Topic); writeMessage(ReceivedMessage); dynamic stuff = JsonConvert.DeserializeObject(ReceivedMessage); if (!(stuff is long) && joystick != null) { String type = stuff["type"]; switch (type.ToLower()) { case "b": UInt32 bi = stuff["index"]; if (bi <= nButtons) { joystick.SetBtn(true, id, bi); } break; case "j": HID_USAGES hv; String index = stuff["index"]; Int32 value = stuff["value"]; if (value > maxval) { //value = Convert.ToInt32(maxval); } if (Enum.TryParse(index, out hv)) { if (Enum.IsDefined(typeof(HID_USAGES), hv)) { joystick.SetAxis(value, id, hv); } } break; default: break; } } }
static public void Setjoystick(int X, int Y, int Z, int XR, int YR, int ZR, bool aButton) { joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X); joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y); joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z); joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX); joystick.SetAxis(YR, id, HID_USAGES.HID_USAGE_RY); joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ); joystick.SetBtn(aButton, id, 1); //string values = string.Format("X:{0,6:#####} Y:{1,6:#####} Z:{2,6:#####} XR:{3,6:#####} YR:{4,6:#####} ZR:{5,6:#####}", X,Y,Z,XR,YR,ZR); //Console.WriteLine(values); }
private void timer_joystick_output_Tick(object sender, EventArgs e) { getGameInfo(); //get location/speed from the game updatebuttonstate(); //just sets the boxes next to the labels as red or green //control the virtual joystick res = joystick.SetAxis(tb_steering.Maximum - tb_steering.Value, id, HID_USAGES.HID_USAGE_X); //res = joystick.SetAxis(tb_speed.Maximum - tb_speed.Value, id, HID_USAGES.HID_USAGE_Y);//if you want to control speed, this could also be used //res = joystick.SetAxis(tb_speed.Maximum - tb_speed.Value, id, HID_USAGES.HID_USAGE_Z); //set button state res = joystick.SetBtn(b1, id, 1); res = joystick.SetBtn(b2, id, 2); res = joystick.SetBtn(b3, id, 3); res = joystick.SetBtn(b4, id, 4); res = joystick.SetBtn(b5, id, 5); res = joystick.SetBtn(b6, id, 6); res = joystick.SetBtn(b7, id, 7); res = joystick.SetBtn(b8, id, 8); }
private static void Input_ChannelMessageReceived(object sender, ChannelMessageEventArgs e) { Console.WriteLine("Input: MIDI, Channel: " + e.Message.MidiChannel + " Data1: " + e.Message.Data1 + " Data2: " + e.Message.Data2); var target = stat_mapping.GetJoyTarget(e.Message.MidiChannel, e.Message.Data1); if (target != null) { if (target.Btn != 0) { bool state = e.Message.Data2 != 0; Console.WriteLine("Output: VJoy " + target.JoyId + ", set button " + target.Btn + " = " + state); stat_vJoy.SetBtn(state, target.JoyId, target.Btn); } else // axis { int hidValue = (int)Math.Round(e.Message.Data2 * MidiToAxisFactor); Console.WriteLine("Output: VJoy " + target.JoyId + ", set axis " + target.Axis + " = " + hidValue); stat_vJoy.SetAxis(hidValue, target.JoyId, target.Axis); } } }
private void SetGamepadItem(byte[] values, int index, GamepadConfigurationItem config) { double value = values[index]; if (config.Type == GamepadItemType.Axis) { long maxAxisValue = 0; var targetAxis = config.TargetUsage ?? HID_USAGES.HID_USAGE_X; _vJoy.GetVJDAxisMax(_gamepadId, targetAxis, ref maxAxisValue); value = NormalizeAxis((byte)value, config.ConvertAxis ?? false); if (config.InvertAxis ?? false) { value = InvertNormalizedAxis(value); } _vJoy.SetAxis((int)(value * maxAxisValue), _gamepadId, targetAxis); } else if (config.Type == GamepadItemType.Button) { _vJoy.SetBtn(ConvertToButtonState((byte)value), _gamepadId, config.TargetButtonId ?? 0); } }
private void OnKeyPressed(object sender, RawInputEventArg e) { if (detecting) { if (!keyboards.ContainsKey(e.KeyPressEvent.DeviceHandle)) { keyboards.Add(e.KeyPressEvent.DeviceHandle, new Keyboard(e.KeyPressEvent.DeviceHandle, e.KeyPressEvent.DeviceName)); comboBox1.Items.Add(e.KeyPressEvent.DeviceHandle); } vJoyBox.CheckedChanged -= vJoyBox_CheckedChanged; vJoyBox.Checked = keyboards[e.KeyPressEvent.DeviceHandle].vJoyEnabled; vJoyBox.CheckedChanged += vJoyBox_CheckedChanged; LSAutorunBox.CheckedChanged -= LSAutorunBox_CheckedChanged; LSAutorunBox.Checked = keyboards[e.KeyPressEvent.DeviceHandle].LSAutoRun; LSAutorunBox.CheckedChanged += LSAutorunBox_CheckedChanged; //labelCurrentKb.Text = $"Current Keyboard: {e.KeyPressEvent.DeviceHandle.ToString()}"; currentHandle = e.KeyPressEvent.DeviceHandle; comboBox1.SelectedItem = currentHandle; /* * inputBox_A.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.A) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.A] : ""; * inputBox_B.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.B) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.B] : ""; * inputBox_X.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.X) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.X] : ""; * inputBox_Y.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.Y) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.Y] : ""; * inputBox_L.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.Y) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.L] : ""; * inputBox_R.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.Y) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.R] : ""; * inputBox_Z.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.Y) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.Z] : ""; * inputBox_START.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.Y) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.START] : ""; * * inputBox_LSUP.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.LSUP) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.LSUP] : ""; * inputBox_LSDOWN.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.LSDOWN) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.LSDOWN] : ""; * inputBox_LSLEFT.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.LSLEFT) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.LSLEFT] : ""; * inputBox_LSRIGHT.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.LSRIGHT) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.LSRIGHT] : ""; * inputBox_LSMOD.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.LSMOD) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.LSMOD] : ""; * * inputBox_RSUP.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.RSUP) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.RSUP] : ""; * inputBox_RSDOWN.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.RSDOWN) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.RSDOWN] : ""; * inputBox_RSLEFT.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.RSLEFT) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.RSLEFT] : ""; * inputBox_RSRIGHT.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.RSRIGHT) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.RSRIGHT] : ""; * * inputBox_DUP.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.DUP) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.DUP] : ""; * inputBox_DDOWN.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.DDOWN) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.DDOWN] : ""; * inputBox_DLEFT.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.DLEFT) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.DLEFT] : ""; * inputBox_DRIGHT.Text = keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsKey(ButtonEnum.DRIGHT) ? keyboards[e.KeyPressEvent.DeviceHandle].binds[ButtonEnum.DRIGHT] : ""; * * LSAutorunBox.Checked = keyboards[e.KeyPressEvent.DeviceHandle].LSAutoRun; * LSAutorunBox.Checked = keyboards[e.KeyPressEvent.DeviceHandle].RSAutoRun; */ detecting = false; } label14.Text = $"{e.KeyPressEvent.DeviceHandle.ToString()}_{e.KeyPressEvent.VKeyName}_{(e.KeyPressEvent.Message == 256 ? "PRESS" : "RELEASE") }"; if (focusedBox != null) { if (focusedBox == inputBox_LSUP) { keyboards[currentHandle].binds[ButtonEnum.LSUP] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_LSDOWN) { keyboards[currentHandle].binds[ButtonEnum.LSDOWN] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_LSLEFT) { keyboards[currentHandle].binds[ButtonEnum.LSLEFT] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_LSRIGHT) { keyboards[currentHandle].binds[ButtonEnum.LSRIGHT] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_LSMOD) { keyboards[currentHandle].binds[ButtonEnum.LSMOD] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_RSUP) { keyboards[currentHandle].binds[ButtonEnum.RSUP] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_RSDOWN) { keyboards[currentHandle].binds[ButtonEnum.RSDOWN] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_RSLEFT) { keyboards[currentHandle].binds[ButtonEnum.RSLEFT] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_RSRIGHT) { keyboards[currentHandle].binds[ButtonEnum.RSRIGHT] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_A) { keyboards[currentHandle].binds[ButtonEnum.A] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_B) { keyboards[currentHandle].binds[ButtonEnum.B] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_X) { keyboards[currentHandle].binds[ButtonEnum.X] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_Y) { keyboards[currentHandle].binds[ButtonEnum.Y] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_Z) { keyboards[currentHandle].binds[ButtonEnum.Z] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_L) { keyboards[currentHandle].binds[ButtonEnum.L] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_R) { keyboards[currentHandle].binds[ButtonEnum.R] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_START) { keyboards[currentHandle].binds[ButtonEnum.START] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_DUP) { keyboards[currentHandle].binds[ButtonEnum.DUP] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_DDOWN) { keyboards[currentHandle].binds[ButtonEnum.DDOWN] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_DLEFT) { keyboards[currentHandle].binds[ButtonEnum.DLEFT] = e.KeyPressEvent.VKeyName; } else if (focusedBox == inputBox_DRIGHT) { keyboards[currentHandle].binds[ButtonEnum.DRIGHT] = e.KeyPressEvent.VKeyName; } focusedBox.Text = e.KeyPressEvent.VKeyName; focusedBox = null; label1.Focus(); } else { if (keyboards.ContainsKey(e.KeyPressEvent.DeviceHandle)) { if (keyboards[e.KeyPressEvent.DeviceHandle].binds.ContainsValue(e.KeyPressEvent.VKeyName)) { var button = keyboards[e.KeyPressEvent.DeviceHandle].binds.FirstOrDefault(x => x.Value == e.KeyPressEvent.VKeyName).Key; switch (button) { case ButtonEnum.A: virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 1); break; case ButtonEnum.B: virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 2); break; case ButtonEnum.X: virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 3); break; case ButtonEnum.Y: virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 4); break; case ButtonEnum.L: virtualJoy.SetAxis(e.KeyPressEvent.Message == 256 ? 32768 : 0, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_Z); break; case ButtonEnum.R: virtualJoy.SetAxis(e.KeyPressEvent.Message == 256 ? 32768 : 0, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_RZ); break; case ButtonEnum.Z: virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 5); break; case ButtonEnum.START: virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 8); break; case ButtonEnum.LSUP: if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].LSUP = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].LSUP = 0; } virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetLSY(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_Y); break; case ButtonEnum.LSDOWN: if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].LSDOWN = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].LSDOWN = 0; } virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetLSY(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_Y); break; case ButtonEnum.LSLEFT: if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].LSLEFT = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].LSLEFT = 0; } virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetLSX(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_X); break; case ButtonEnum.LSRIGHT: if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].LSRIGHT = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].LSRIGHT = 0; } virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetLSX(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_X); break; case ButtonEnum.LSMOD: if (keyboards[e.KeyPressEvent.DeviceHandle].LSAutoRun) { if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].LSMOD = 2; } else { keyboards[e.KeyPressEvent.DeviceHandle].LSMOD = 1; } } else { if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].LSMOD = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].LSMOD = 2; } } break; case ButtonEnum.RSUP: if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].RSUP = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].RSUP = 0; } virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetRSY(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_RY); break; case ButtonEnum.RSDOWN: if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].RSDOWN = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].RSDOWN = 0; } virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetRSY(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_RY); break; case ButtonEnum.RSLEFT: if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].RSLEFT = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].RSLEFT = 0; } virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetRSX(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_RX); break; case ButtonEnum.RSRIGHT: if (e.KeyPressEvent.Message == 256) { keyboards[e.KeyPressEvent.DeviceHandle].RSRIGHT = 1; } else { keyboards[e.KeyPressEvent.DeviceHandle].RSRIGHT = 0; } virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetRSX(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_RX); break; case ButtonEnum.DUP: /* * if (e.KeyPressEvent.Message == 256) * { * keyboards[e.KeyPressEvent.DeviceHandle].DUP = 1; * } * else * { * keyboards[e.KeyPressEvent.DeviceHandle].DUP = 0; * } * virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetDY(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_SL0); * break; */ virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 9); break; case ButtonEnum.DDOWN: /* * if (e.KeyPressEvent.Message == 256) * { * keyboards[e.KeyPressEvent.DeviceHandle].DDOWN = 1; * } * else * { * keyboards[e.KeyPressEvent.DeviceHandle].DDOWN = 0; * } * virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetDY(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_SL0); * break; */ virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 10); break; case ButtonEnum.DLEFT: /* * if (e.KeyPressEvent.Message == 256) * { * keyboards[e.KeyPressEvent.DeviceHandle].DLEFT = 1; * } * else * { * keyboards[e.KeyPressEvent.DeviceHandle].DLEFT = 0; * } * virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetDX(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_SL1); * break; */ virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 11); break; case ButtonEnum.DRIGHT: /* * if (e.KeyPressEvent.Message == 256) * { * keyboards[e.KeyPressEvent.DeviceHandle].DRIGHT = 1; * } * else * { * keyboards[e.KeyPressEvent.DeviceHandle].DRIGHT = 0; * } * virtualJoy.SetAxis(keyboards[e.KeyPressEvent.DeviceHandle].GetDX(), keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, HID_USAGES.HID_USAGE_SL1); */ virtualJoy.SetBtn(e.KeyPressEvent.Message == 256, keyboards[e.KeyPressEvent.DeviceHandle].vJoyId, 12); break; } } } } }
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 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"); // 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); 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); #if ROBUST bool res; // Reset this device to default values joystick.ResetVJD(id); // Feed the device in endless loop while (true) { // 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) #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
static void Main(string[] args) { SerialPort _port; float[] Thetas; joystick = new vJoy(); Thetas = new float[3]; Thetas[0] = 0; Thetas[1] = 0; Thetas[2] = 0; VJoyActivation(); Console.WriteLine("insert COM port name: "); string COMportName = Console.ReadLine(); Console.WriteLine("\ninsert baud rate: "); int baudRate = Int32.Parse(Console.ReadLine()); _port = new SerialPort(); _port.PortName = COMportName; _port.BaudRate = baudRate; _port.Parity = Parity.None; _port.DataBits = 8; _port.StopBits = StopBits.One; _port.ReadTimeout = 500; _port.WriteTimeout = 500; _port.Open(); long maxval = 0; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); while (true) { try { string a = _port.ReadLine(); string[] substrings = a.Split('|'); if (substrings.Length == 3) { Thetas[0] = clamp(float.Parse(substrings[0]), -50, 50); Thetas[1] = clamp(float.Parse(substrings[1]), -50, 50); Thetas[2] = float.Parse(substrings[2]); Console.WriteLine("ThetaX={0} ThetaY={1} ThetaZ={2}", Thetas[0], Thetas[1], Thetas[2]); } } catch { } //normalizing xrot and mapping to full range ans letting x maxRot=50deg joystick.SetAxis(Convert.ToInt32(((Thetas[0] / 100) + 0.5) * maxval), id, HID_USAGES.HID_USAGE_X); joystick.SetAxis(Convert.ToInt32(((Thetas[1] / 100) + 0.5) * maxval), id, HID_USAGES.HID_USAGE_Y); //threshold of btn=20 deg (btn1=R1 btn2=L1) if (Thetas[2] > 20) { joystick.SetBtn(true, id, 1); joystick.SetBtn(false, id, 2); } else if (Thetas[2] < -20) { joystick.SetBtn(true, id, 2); joystick.SetBtn(false, id, 1); } else { joystick.SetBtn(false, id, 1); joystick.SetBtn(false, id, 2); } Thread.Sleep(20); } }
} // Main public static IEnumerator TestCoroutine() { int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(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 Debug.Log("start"); while (true) { // 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; } yield return(new WaitForFixedUpdate()); } // While (Robust) }
static void Main(string[] args) { Console.WriteLine("Setting up virtual device..."); joystick = new vJoy(); // 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; joystick.ResetVJD(id); 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; } if (!(joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X) && joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y) && joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX) && joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY) && joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z) && joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ) && joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_SL0) && joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_SL1) )) { Console.WriteLine("VJoy Device " + id + " does not support enough axes for SkyController. Make sure device has at least 8 axes"); 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); } // 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); } deviceState = new SCState(); Console.WriteLine("Starting net receiver..."); UdpClient listener = new UdpClient(8899); IPEndPoint ep = null; byte[] data = new byte[128]; listener.JoinMulticastGroup(IPAddress.Parse("230.0.0.1")); Console.WriteLine("Waiting for data on 230.0.0.1:8899..."); data = listener.Receive(ref ep); Console.WriteLine("Receiving from " + ep.Address.ToString() + ":" + ep.Port.ToString() + "..."); joystick.ResetVJD(id); int CursorRow = Console.CursorTop; uint pId = 0; long axisMax = 0; joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref axisMax); while (true) { //System.Threading.Thread.Sleep(10); data = listener.Receive(ref ep); pId = BitConverter.ToUInt32(data, 0); deviceState.Deserialize(data, 4); Console.CursorLeft = 0; Console.CursorTop = CursorRow; Console.WriteLine("Received " + data.Length + " bytes. Packet ID: " + pId); //Console.WriteLine("Yaw: " + deviceState._axis0.ToString("0.00")); //Console.WriteLine("Gaz: " + deviceState._axis1.ToString("0.00")); //Console.WriteLine("Roll: " + deviceState._axis13.ToString("0.00")); //Console.WriteLine("Pitch: " + deviceState._axis2.ToString("0.00")); //Console.WriteLine("LThumb X: " + deviceState._axis14.ToString("0.00")); //Console.WriteLine("LThumb Y: " + deviceState._axis15.ToString("0.00")); //Console.WriteLine("RThumb X: " + deviceState._axis8.ToString("0.00")); //Console.WriteLine("RThumb Y: " + deviceState._axis9.ToString("0.00")); Console.WriteLine("Battery: " + (deviceState._axis10 * 100f).ToString("0.00") + "%"); //joystick.SetAxis((int)(deviceState._axis0 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_X); //joystick.SetAxis((int)(-deviceState._axis1 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_Y); //joystick.SetAxis((int)(deviceState._axis13 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RX); //joystick.SetAxis((int)(deviceState._axis2 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RY); //joystick.SetAxis((int)(deviceState._axis3 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_Z); //joystick.SetAxis((int)(deviceState._axis14 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RZ); //joystick.SetAxis((int)(deviceState._axis8 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_SL0); //joystick.SetAxis((int)(deviceState._axis9 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_SL1); joystick.SetAxis((int)(deviceState._axis13 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_X); joystick.SetAxis((int)(-deviceState._axis2 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_Y); joystick.SetAxis((int)(-deviceState._axis1 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_Z); joystick.SetAxis((int)(deviceState._axis0 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RX); joystick.SetAxis((int)(deviceState._axis8 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RY); joystick.SetAxis((int)(deviceState._axis9 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_RZ); joystick.SetAxis((int)(deviceState._axis3 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_SL0); joystick.SetAxis((int)(deviceState._axis14 * _axisRange + _axisRange), id, HID_USAGES.HID_USAGE_SL1); } }