[BTT 3.202][macOS 10.15 Beta 19A558d] Touch Bar Widgets erroneously enter & stay in "alt/option" mode upon arrow key press

Describe the bug
If any of the arrow keys are pressed (up/down/left/right), then the touch bar widgets which I have set to display alternate icons when alt/option is pressed while switch to their alternate icons and actions (alternative action is based on applescript). They will remain in this alt/option mode until any other input is received; e.g. moving the cursor, clicking the mouse, pressing any non-arrow key on the keyboard.

Affected input device (e.g. MacBook Trackpad, Magic Mouse/Trackpad, Touch Bar, etc.):
Touch Bar


Device information:

  • Type of Mac: 2018 15" MacBook Pro
  • macOS version: 10.15 Beta (Build 19A558d)
  • BetterTouchTool version: 3.202

Additional information (e.g. StackTraces, related issues, screenshots, workarounds, etc.):
This is weird because it actually may be an error with the applescript rather than BTT. Basically, I have an applescript which checks whether the option key is pressed. This applescript is not only run continuously to decide the button's icon, but it is also run upon the button's press to either run the volume up action or "small" volume up action. There is the same thing for volume down and brightness for main display or keyboard upon alt/option press. Check out the attached preset to see it in full detail. Essentials v1.5.1.bttpreset (442.6 KB)

Note: Before bug reporting, please make sure you have the latest version of BetterTouchTool and that you have already tried to restart your system :-). If you encounter a crash, please attach a crash log from the macOS Console.app from the "User Diagnostic Reports" section.

Anyone have any ideas? Can you reproduce the issue with this single button:
Try pressing the button normally. It should do a full volume step (1/16) up. Then, press an arrow key and wait 1 second. Press the button again, and, even though you're not pressing alt/option, it should do a quarter volume step (1/64) up. The arrow key almost seems to emulate the alt/option key indefinitely.

Figured it out. It's a bug with the AppleScript (maybe that was obvious?), so I changed from using the Cocoa framework to the Foundation and AppKit frameworks. The following AppleScript code works, but not for the fn key. Since I pretty much only care about the option key, it doesn't matter at all for me.

use framework "Foundation"
use framework "AppKit"

property NSCapsLockMask : a reference to 65536
property NSShiftKeyMask : a reference to 131072
property NSControlKeyMask : a reference to 262144
property NSOptionKeyMask : a reference to 524288
property NSCommandKeyMask : a reference to 1048576
property NSFunctionKeyMask : a reference to 8388608
property NSEvent : a reference to current application's NSEvent

on KeyPressed(KeyName)
    if KeyName = "caps lock" then
	set TheMask to NSCapsLockMask
    else if KeyName = "shift" then
	set TheMask to NSShiftKeyMask
    else if KeyName = "control" then
	set TheMask to NSControlKeyMask
    else if KeyName = "option" then
	set TheMask to NSOptionKeyMask
    else if KeyName = "command" then
	set TheMask to NSCommandKeyMask
	return false
        end if

    set MFlags to NSEvent's modifierFlags() as integer
    if ((MFlags div TheMask) mod 2) = 0 then
	return false
	return true
    end if
end KeyPressed

on getModifiersDown()
    set modifierKeysDown to {command_down:false, option_down:false, control_down:false, shift_down:false, capslock_down:false}
    set KeyFlags to NSEvent's modifierFlags() as integer

    if ((KeyFlags div NSCommandKeyMask) mod 2) is not 0 then
	set command_down of modifierKeysDown to true
    end if
    if ((KeyFlags div NSOptionKeyMask) mod 2) is not 0 then
	set option_down of modifierKeysDown to true
    end if
    if ((KeyFlags div NSControlKeyMask) mod 2) is not 0 then
	set control_down of modifierKeysDown to true
    end if
    if ((KeyFlags div NSShiftKeyMask) mod 2) is not 0 then
	set shift_down of modifierKeysDown to true
    end if
    if ((KeyFlags div NSCapsLockMask) mod 2) is not 0 then
	set capslock_down of modifierKeysDown to true
    end if

    # NOTE: Buggy
    # Function key erroneously sets to true when the last key pressed was an arrow key

    #if ((KeyFlags div NSFunctionKeyMask) mod 2) is not 0 then
    #	set fn_down of modifierKeysDown to true
    #end if

    return modifierKeysDown
end getModifiersDown

set modifierKeysDown to getModifiersDown()
if (option_down of modifierKeysDown is false) then
    tell application "BetterTouchTool" to trigger_action "{\"BTTPredefinedActionType\":24}"
    tell application "BetterTouchTool" to trigger_action "{\"BTTPredefinedActionType\":198}"
end if
return modifierKeysDown