diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 35fe15e..504af9a 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -2257,34 +2257,17 @@ namespace DS4Windows if (synced && !d.isCharging()) { ConnectionType deviceConn = d.getConnectionType(); - bool exclusive = /*tempBool =*/ d.isExclusive(); + //bool exclusive = /*tempBool =*/ d.isExclusive(); if (deviceConn == ConnectionType.BT) { d.DisconnectBT(); + ReleaseActionKeys(action, device); + return; } - else if (deviceConn == ConnectionType.SONYWA && exclusive) + else if (deviceConn == ConnectionType.SONYWA) { - d.DisconnectDongle(); + action.pressRelease = true; } - - //foreach (DS4Controls dc in action.trigger) - for (int i = 0, arlen = action.trigger.Count; i < arlen; i++) - { - DS4Controls dc = action.trigger[i]; - DS4ControlSettings dcs = getDS4CSetting(device, dc); - if (dcs.action != null) - { - if (dcs.actionType == DS4ControlSettings.ActionType.Key) - InputMethods.performKeyRelease((ushort)dcs.action); - else if (dcs.actionType == DS4ControlSettings.ActionType.Macro) - { - int[] keys = (int[])dcs.action; - for (int j = 0, keysLen = keys.Length; j < keysLen; j++) - InputMethods.performKeyRelease((ushort)keys[j]); - } - } - } - return; } } else if (action.typeID == SpecialAction.ActionTypeId.BatteryCheck) @@ -2354,6 +2337,22 @@ namespace DS4Windows actionDone[index].dev[device] = false; } } + else if (action.typeID == SpecialAction.ActionTypeId.DisconnectBT && action.pressRelease) + { + actionFound = true; + DS4Device d = ctrl.DS4Controllers[device]; + ConnectionType deviceConn = d.getConnectionType(); + if (deviceConn == ConnectionType.SONYWA && d.isSynced()) + { + if (d.isDS4Idle()) + { + d.DisconnectDongle(); + ReleaseActionKeys(action, device); + actionDone[index].dev[device] = false; + action.pressRelease = false; + } + } + } else if (action.typeID != SpecialAction.ActionTypeId.Key && action.typeID != SpecialAction.ActionTypeId.XboxGameDVR && action.typeID != SpecialAction.ActionTypeId.MultiAction) @@ -2625,6 +2624,27 @@ namespace DS4Windows } } + private static void ReleaseActionKeys(SpecialAction action, int device) + { + //foreach (DS4Controls dc in action.trigger) + for (int i = 0, arlen = action.trigger.Count; i < arlen; i++) + { + DS4Controls dc = action.trigger[i]; + DS4ControlSettings dcs = getDS4CSetting(device, dc); + if (dcs.action != null) + { + if (dcs.actionType == DS4ControlSettings.ActionType.Key) + InputMethods.performKeyRelease((ushort)dcs.action); + else if (dcs.actionType == DS4ControlSettings.ActionType.Macro) + { + int[] keys = (int[])dcs.action; + for (int j = 0, keysLen = keys.Length; j < keysLen; j++) + InputMethods.performKeyRelease((ushort)keys[j]); + } + } + } + } + // Play macro as a background task. Optionally the new macro play waits for completion of a previous macro execution (synchronized macro special action). // Macro steps are defined either as macrostr string value, macroLst list object or as macroArr integer array. Only one of these should have a valid macro definition when this method is called. // If the macro definition is a macroStr string value then it will be converted as integer array on the fl. If steps are already defined as list or array of integers then there is no need to do type cast conversion.