public static void SetButtonState(this Xbox360Report report, Xbox360Buttons button, bool state) { if (state) { report.Buttons |= (ushort)button; } else { report.Buttons &= (ushort)~button; } }
public void SetButtonState(Xbox360Buttons button, bool state) { if (state) { Buttons |= (ushort)button; } else { Buttons &= (ushort)~button; } }
private void ParseKey(Xbox360Buttons target, Xbox360Report controllerReport, uint dwFlags = 0) { if ((int)target < 0) { return; } if (dwFlags == 0) { controllerReport.SetButtonState(target, true); } else { controllerReport.SetButtonState(target, false); } }
public override void ConvertandSendReport(DS4State state, int device) { Xbox360Buttons tempButtons = 0; unchecked { if (state.Share) { tempButtons |= Xbox360Buttons.Back; } if (state.L3) { tempButtons |= Xbox360Buttons.LeftThumb; } if (state.R3) { tempButtons |= Xbox360Buttons.RightThumb; } if (state.Options) { tempButtons |= Xbox360Buttons.Start; } if (state.DpadUp) { tempButtons |= Xbox360Buttons.Up; } if (state.DpadRight) { tempButtons |= Xbox360Buttons.Right; } if (state.DpadDown) { tempButtons |= Xbox360Buttons.Down; } if (state.DpadLeft) { tempButtons |= Xbox360Buttons.Left; } if (state.L1) { tempButtons |= Xbox360Buttons.LeftShoulder; } if (state.R1) { tempButtons |= Xbox360Buttons.RightShoulder; } if (state.Triangle) { tempButtons |= Xbox360Buttons.Y; } if (state.Circle) { tempButtons |= Xbox360Buttons.B; } if (state.Cross) { tempButtons |= Xbox360Buttons.A; } if (state.Square) { tempButtons |= Xbox360Buttons.X; } if (state.PS) { tempButtons |= Xbox360Buttons.Guide; } report.SetButtonsFull(tempButtons); } report.LeftTrigger = state.L2; report.RightTrigger = state.R2; SASteeringWheelEmulationAxisType steeringWheelMappedAxis = Global.GetSASteeringWheelEmulationAxis(device); switch (steeringWheelMappedAxis) { case SASteeringWheelEmulationAxisType.None: report.LeftThumbX = AxisScale(state.LX, false); report.LeftThumbY = AxisScale(state.LY, true); report.RightThumbX = AxisScale(state.RX, false); report.RightThumbY = AxisScale(state.RY, true); break; case SASteeringWheelEmulationAxisType.LX: report.LeftThumbX = (short)state.SASteeringWheelEmulationUnit; report.LeftThumbY = AxisScale(state.LY, true); report.RightThumbX = AxisScale(state.RX, false); report.RightThumbY = AxisScale(state.RY, true); break; case SASteeringWheelEmulationAxisType.LY: report.LeftThumbX = AxisScale(state.LX, false); report.LeftThumbY = (short)state.SASteeringWheelEmulationUnit; report.RightThumbX = AxisScale(state.RX, false); report.RightThumbY = AxisScale(state.RY, true); break; case SASteeringWheelEmulationAxisType.RX: report.LeftThumbX = AxisScale(state.LX, false); report.LeftThumbY = AxisScale(state.LY, true); report.RightThumbX = (short)state.SASteeringWheelEmulationUnit; report.RightThumbY = AxisScale(state.RY, true); break; case SASteeringWheelEmulationAxisType.RY: report.LeftThumbX = AxisScale(state.LX, false); report.LeftThumbY = AxisScale(state.LY, true); report.RightThumbX = AxisScale(state.RX, false); report.RightThumbY = (short)state.SASteeringWheelEmulationUnit; break; case SASteeringWheelEmulationAxisType.L2R2: report.LeftTrigger = report.RightTrigger = 0; if (state.SASteeringWheelEmulationUnit >= 0) { report.LeftTrigger = (Byte)state.SASteeringWheelEmulationUnit; } else { report.RightTrigger = (Byte)state.SASteeringWheelEmulationUnit; } goto case SASteeringWheelEmulationAxisType.None; case SASteeringWheelEmulationAxisType.VJoy1X: case SASteeringWheelEmulationAxisType.VJoy2X: DS4Windows.VJoyFeeder.vJoyFeeder.FeedAxisValue(state.SASteeringWheelEmulationUnit, ((((uint)steeringWheelMappedAxis) - ((uint)SASteeringWheelEmulationAxisType.VJoy1X)) / 3) + 1, DS4Windows.VJoyFeeder.HID_USAGES.HID_USAGE_X); goto case SASteeringWheelEmulationAxisType.None; case SASteeringWheelEmulationAxisType.VJoy1Y: case SASteeringWheelEmulationAxisType.VJoy2Y: DS4Windows.VJoyFeeder.vJoyFeeder.FeedAxisValue(state.SASteeringWheelEmulationUnit, ((((uint)steeringWheelMappedAxis) - ((uint)SASteeringWheelEmulationAxisType.VJoy1X)) / 3) + 1, DS4Windows.VJoyFeeder.HID_USAGES.HID_USAGE_Y); goto case SASteeringWheelEmulationAxisType.None; case SASteeringWheelEmulationAxisType.VJoy1Z: case SASteeringWheelEmulationAxisType.VJoy2Z: DS4Windows.VJoyFeeder.vJoyFeeder.FeedAxisValue(state.SASteeringWheelEmulationUnit, ((((uint)steeringWheelMappedAxis) - ((uint)SASteeringWheelEmulationAxisType.VJoy1X)) / 3) + 1, DS4Windows.VJoyFeeder.HID_USAGES.HID_USAGE_Z); goto case SASteeringWheelEmulationAxisType.None; default: // Should never come here but just in case use the NONE case as default handler.... goto case SASteeringWheelEmulationAxisType.None; } cont.SendReport(report); }
public VigemXbox360ButtonMapping(Xbox360Buttons button) { Type = button; }
public void SetButtons(Xbox360Buttons buttons) { Buttons = (ushort)buttons; }
public static void SetButtonsFull(this Xbox360Report report, Xbox360Buttons buttons) { report.Buttons = (ushort)buttons; }
/// <summary> /// handles key events /// </summary> /// <param name="eventType"></param> /// <param name="vkCode"></param> /// <returns>1 if the event has been handled, 0 if the key was not mapped, and -1 if the exit key has been pressed</returns> public int keyEvent(int eventType, Keys vkCode) { int handled = 0; if (enabled) { for (int i = 0; i < config.PadCount; i++) { int padNumberForDisplay = i + 1; string sectionName = "pad" + (padNumberForDisplay); // is the key pressed mapped to a button? string mappedButton = config.getCurrentMapping()[sectionName][vkCode.ToString()]; if (mappedButton != null) { if (buttonsDict.ContainsKey(mappedButton)) { if ((eventType == WM_KEYDOWN) || (eventType == WM_SYSKEYDOWN)) { // if we already notified the virtual pad, don't do it again Xbox360Buttons pressedButton = buttonsDict[mappedButton]; if (pressedButtons[i].Contains(pressedButton)) { handled = 1; break; } // store the state of the button pressedButtons[i].Add(pressedButton); reports[i].SetButtonState(pressedButton, true); if (log.IsDebugEnabled) { log.Debug($"pad{padNumberForDisplay} {mappedButton} down"); } } else { Xbox360Buttons pressedButton = buttonsDict[mappedButton]; reports[i].SetButtonState(pressedButton, false); // remove the button state from our own set pressedButtons[i].Remove(pressedButton); if (log.IsDebugEnabled) { log.Debug($"pad{padNumberForDisplay} {mappedButton} up"); } } controllers[i].SendReport(reports[i]); handled = 1; break; } else if (axesDict.ContainsKey(mappedButton)) { KeyValuePair <Xbox360Axes, short> axisValuePair = axesDict[mappedButton]; if ((eventType == WM_KEYDOWN) || (eventType == WM_SYSKEYDOWN)) { reports[i].SetAxis(axisValuePair.Key, axisValuePair.Value); if (log.IsDebugEnabled) { log.Debug($"pad{padNumberForDisplay} {mappedButton} down"); } } else { reports[i].SetAxis(axisValuePair.Key, 0x0); if (log.IsDebugEnabled) { log.Debug($"pad{padNumberForDisplay} {mappedButton} up"); } } controllers[i].SendReport(reports[i]); handled = 1; break; } } } } if (handled == 0) { // handle the enable toggle key even if disabled (otherwise there's not much point to it...) string enableButton = config.getCurrentMapping()["config"][vkCode.ToString()]; if ("enableToggle".Equals(enableButton)) { if ((eventType == WM_KEYDOWN) || (eventType == WM_SYSKEYDOWN)) { ToggleEnabled(); if (log.IsInfoEnabled) { log.Info($"enableToggle down; enabled={enabled}"); } } handled = 1; } else if ("enable".Equals(enableButton)) { if ((eventType == WM_KEYDOWN) || (eventType == WM_SYSKEYDOWN)) { Enable(); if (log.IsInfoEnabled) { log.Info($"enable down; enabled={enabled}"); } } handled = 1; } else if ("disable".Equals(enableButton)) { if ((eventType == WM_KEYDOWN) || (eventType == WM_SYSKEYDOWN)) { Disable(); if (log.IsInfoEnabled) { log.Info($"disable down; enabled={enabled}"); } } handled = 1; } // key that exits the software string configButton = config.getCurrentMapping()["config"][vkCode.ToString()]; if ("exit".Equals(configButton)) { handled = -1; } else if ((configButton != null) && configButton.StartsWith("config")) { if ((eventType == WM_KEYDOWN) || (eventType == WM_SYSKEYDOWN)) { int index = Int32.Parse(configButton.Substring(configButton.Length - 1)); if (log.IsInfoEnabled) { log.Info($"Switching to mapping {index}"); } config.CurrentMappingIndex = index; } handled = 1; } } if (handled == 0 && enabled && log.IsWarnEnabled) { log.Warn($"unmapped button {vkCode.ToString()}"); } return(handled); }
public void SetButtonState(Xbox360Buttons btn, bool state) { _report.SetButtonState(btn, state); }