From 69b413277a7a9dd7ec394f70682e3738c9b697d0 Mon Sep 17 00:00:00 2001 From: Son-Guhun <22954418+Son-Guhun@users.noreply.github.com> Date: Tue, 8 Dec 2020 16:13:39 -0300 Subject: [PATCH] Fixed unwanted behaviour in OSKeyLib Letting go of the last pressed key will no longer cause previously pressed keys that are still being held down to be considered unpressed. Also implemented BlzIsLocalClientActive check. --- release/trigger/51-ControlState/7-OSKeyLib.j | 28 ++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/release/trigger/51-ControlState/7-OSKeyLib.j b/release/trigger/51-ControlState/7-OSKeyLib.j index dca46aa..f371aae 100644 --- a/release/trigger/51-ControlState/7-OSKeyLib.j +++ b/release/trigger/51-ControlState/7-OSKeyLib.j @@ -265,8 +265,9 @@ struct OSKeys extends array private static trigger eventResponder = null private static trigger executer private static trigger holdExecuter + private static framehandle syncButton private static real array latestTimestamp - private static integer array totalPressedKeys + private static thistype array lastPressedKey private static boolean array isPressedArray[256][24] private static real array timestamp[256][24] @@ -348,7 +349,7 @@ struct OSKeys extends array set key = key + 1 endloop - set totalPressedKeys[pId] = 0 + set lastPressedKey[pId] = 0 endmethod static method getPressedMetaKeys takes player whichPlayer returns integer @@ -399,23 +400,23 @@ struct OSKeys extends array // A key firing a up event while it's already up is a sign of alt-tab/unintended behaviour if isPressedArray[key][pId] then - set totalPressedKeys[pId] = totalPressedKeys[pId] - 1 // only change total count if key was actually pressed before being released set isPressedArray[key][pId] = false endif call TriggerEvaluate(executer) elseif not key.isPressedId(pId) then + set lastPressedKey[pId] = key set latestTimestamp[pId] = Timeline.game.elapsed set timestamp[key][pId] = Timeline.game.elapsed set isPressedArray[key][pId] = true - set totalPressedKeys[pId] = totalPressedKeys[pId] + 1 call TriggerEvaluate(executer) if key == RETURN then call resetKeys(pId) endif else + set lastPressedKey[pId] = key set latestTimestamp[pId] = Timeline.game.elapsed call TriggerEvaluate(holdExecuter) @@ -430,20 +431,37 @@ struct OSKeys extends array loop exitwhen pId >= bj_MAX_PLAYERS - if totalPressedKeys[pId] > 0 and Timeline.game.elapsed - latestTimestamp[pId] > TIMEOUT then + if lastPressedKey[pId] != 0 and lastPressedKey[pId].isPressedId(pId) and Timeline.game.elapsed - latestTimestamp[pId] > TIMEOUT then call resetKeys(pId) endif set pId = pId + 1 endloop + if not BlzIsLocalClientActive() and lastPressedKey[User.fromLocal()] != 0 then + call BlzFrameClick(syncButton) + endif + + endmethod + + private static method onSync takes nothing returns nothing + if lastPressedKey[User[GetTriggerPlayer()]] != 0 then + call resetKeys(User[GetTriggerPlayer()]) + endif endmethod private static method onStart takes nothing returns nothing local trigger trig = CreateTrigger() local User p local thistype key = 0 + local framehandle frame = BlzCreateFrameByType("BUTTON", "OSKeysSyncButton", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "",0) + + call TriggerAddAction(trig, function thistype.onSync) + call BlzTriggerRegisterFrameEvent(trig, frame, FRAMEEVENT_CONTROL_CLICK) + call BlzFrameSetVisible(frame, false) + set .syncButton = frame + set trig = CreateTrigger() set .eventResponder = trig call TimerStart(GetExpiredTimer(), ACCURACY, true, function thistype.onTimer)