public DS4Device(HidDevice device, int controllerID) { hid_device = device; deviceNum = controllerID; isUSB = Device.Capabilities.InputReportByteLength == 64; MACAddr = Device.readSerial(); if (isUSB) { outputData = new byte[Device.Capabilities.OutputReportByteLength]; } else { btInputData = new byte[Device.Capabilities.InputReportByteLength]; outputData = new byte[78]; } isTouchEnabled = Global.getTouchEnabled(deviceNum); touchpad = new Touchpad(deviceNum); mouse = new Mouse(deviceNum); touchpad.TouchButtonDown += mouse.touchButtonDown; touchpad.TouchButtonUp += mouse.touchButtonUp; touchpad.TouchesBegan += mouse.touchesBegan; touchpad.TouchesMoved += mouse.touchesMoved; touchpad.TouchesEnded += mouse.touchesEnded; Device.MonitorDeviceEvents = true; }
public static void mapButtons(ref DS4State nextState, ref DS4State cState, ref DS4State prevState, Mouse touchpad) { foreach (KeyValuePair<DS4Controls, ushort> customKey in Global.getCustomKeys()) { DS4KeyType keyType = Global.getCustomKeyType(customKey.Key); bool PrevOn = getBoolMapping(customKey.Key, prevState); if (getBoolMapping(customKey.Key, cState)) { resetToDefaultValue(customKey.Key, ref cState); if (!PrevOn) { if (keyType.HasFlag(DS4KeyType.ScanCode)) touchpad.performSCKeyPress(customKey.Value); else touchpad.performKeyPress(customKey.Value); } else if (keyType.HasFlag(DS4KeyType.Repeat)) if (keyType.HasFlag(DS4KeyType.ScanCode)) touchpad.performSCKeyPress(customKey.Value); else touchpad.performKeyPress(customKey.Value); } else if (PrevOn) { if (keyType.HasFlag(DS4KeyType.ScanCode)) touchpad.performSCKeyRelease(customKey.Value); else touchpad.performKeyRelease(customKey.Value); } } bool LX = false, LY = false, RX = false, RY = false; nextState.LX = 127; nextState.LY = 127; nextState.RX = 127; nextState.RY = 127; foreach (KeyValuePair<DS4Controls, X360Controls> customButton in Global.getCustomButtons()) { bool LXChanged = nextState.LX == 127; bool LYChanged = nextState.LY == 127; bool RXChanged = nextState.RX == 127; bool RYChanged = nextState.RY == 127; switch (customButton.Value) { case X360Controls.A: nextState.Cross = getBoolMapping(customButton.Key, cState); break; case X360Controls.B: nextState.Circle = getBoolMapping(customButton.Key, cState); break; case X360Controls.X: nextState.Square = getBoolMapping(customButton.Key, cState); break; case X360Controls.Y: nextState.Triangle = getBoolMapping(customButton.Key, cState); break; case X360Controls.LB: nextState.L1 = getBoolMapping(customButton.Key, cState); break; case X360Controls.LS: nextState.L3 = getBoolMapping(customButton.Key, cState); break; case X360Controls.RB: nextState.R1 = getBoolMapping(customButton.Key, cState); break; case X360Controls.RS: nextState.R3 = getBoolMapping(customButton.Key, cState); break; case X360Controls.DpadUp: nextState.DpadUp = getBoolMapping(customButton.Key, cState); break; case X360Controls.DpadDown: nextState.DpadDown = getBoolMapping(customButton.Key, cState); break; case X360Controls.DpadLeft: nextState.DpadLeft = getBoolMapping(customButton.Key, cState); break; case X360Controls.DpadRight: nextState.DpadRight = getBoolMapping(customButton.Key, cState); break; case X360Controls.Guide: nextState.PS = getBoolMapping(customButton.Key, cState); break; case X360Controls.Back: nextState.Share = getBoolMapping(customButton.Key, cState); break; case X360Controls.Start: nextState.Options = getBoolMapping(customButton.Key, cState); break; case X360Controls.LXNeg: if (LXChanged) { nextState.LX = getXYAxisMapping(customButton.Key, cState); LX = true; } break; case X360Controls.LYNeg: if (LYChanged) { nextState.LY = getXYAxisMapping(customButton.Key, cState); LY = true; } break; case X360Controls.RXNeg: if (RXChanged) { nextState.RX = getXYAxisMapping(customButton.Key, cState); RX = true; } break; case X360Controls.RYNeg: if (RYChanged) { nextState.RY = getXYAxisMapping(customButton.Key, cState); RY = true; } break; case X360Controls.LXPos: if (LXChanged) { nextState.LX = getXYAxisMapping(customButton.Key, cState, true); LX = true; } break; case X360Controls.LYPos: if (LYChanged) { nextState.LY = getXYAxisMapping(customButton.Key, cState, true); LY = true; } break; case X360Controls.RXPos: if (RXChanged) { nextState.RX = getXYAxisMapping(customButton.Key, cState, true); RX = true; } break; case X360Controls.RYPos: if (RYChanged) { nextState.RY = getXYAxisMapping(customButton.Key, cState, true); RY = true; } break; case X360Controls.LT: nextState.L2 = getByteMapping(customButton.Key, cState); break; case X360Controls.RT: nextState.R2 = getByteMapping(customButton.Key, cState); break; case X360Controls.LeftMouse: bool PrevOn = getBoolMapping(customButton.Key, prevState); bool CurOn = getBoolMapping(customButton.Key, cState); if (!PrevOn && CurOn) touchpad.MouseEvent(Mouse.MOUSEEVENTF_LEFTDOWN); else if (PrevOn && !CurOn) touchpad.MouseEvent(Mouse.MOUSEEVENTF_LEFTUP); break; case X360Controls.RightMouse: PrevOn = getBoolMapping(customButton.Key, prevState); CurOn = getBoolMapping(customButton.Key, cState); if (!PrevOn && CurOn) touchpad.MouseEvent(Mouse.MOUSEEVENTF_RIGHTDOWN); else if (PrevOn && !CurOn) touchpad.MouseEvent(Mouse.MOUSEEVENTF_RIGHTUP); break; case X360Controls.MiddleMouse: PrevOn = getBoolMapping(customButton.Key, prevState); CurOn = getBoolMapping(customButton.Key, cState); if (!PrevOn && CurOn) touchpad.MouseEvent(Mouse.MOUSEEVENTF_MIDDLEDOWN); else if (PrevOn && !CurOn) touchpad.MouseEvent(Mouse.MOUSEEVENTF_MIDDLEUP); break; case X360Controls.Unbound: resetToDefaultValue(customButton.Key, ref nextState); break; } } if (!LX) nextState.LX = cState.LX; if (!LY) nextState.LY = cState.LY; if (!RX) nextState.RX = cState.RX; if (!RY) nextState.RY = cState.RY; }