ESC button and keyboard shortcuts not sending key down and key up events

Describe the bug
When the BTT Esc button is pressed, the running application is not getting Key Down and Key Up events for the ESC button. Most games check only Key Down and Key Up events and ignore Key Press events. Also sending KeyBoard shortcuts also doesn't send Key Down and Key Up events. (Of course this could be require adding a slider for how long the key should be held down for before the key up is pressed for keyboard shortcuts)

Affected input device (e.g. MacBook Trackpad, Magic Mouse/Trackpad, Touch Bar, etc.):
Touch Bar
(More of an Output problem than input, all devices are effected if they send keyboard shortcuts.)

Device information:

  • Type of Mac: MacBook Pro (15-inch, 2016)
  • macOS version: 10.14.5 (18F132)
  • BetterTouchTool version: 3.167 (1340)

Additional information (e.g. StackTraces, related issues, screenshots, workarounds, etc.):
The following Apple Script sends Key Down and Key Up codes that have worked in games i have tried.
Games I have verified BTT shortcuts not working in that need this:
Minecraft, Terraria, Binding of Isaac.
This Code i set up for the Esc Key to trigger to make the escape key work in the game Binding of Isaac. without it the game is non-functioning without disabling the Touch Bar. Other Games seem to need the same events to function properly. Although I could put in this script and have for many games for each key i need, The Esc key problem still exists and it's a lot of extra work that your tool could handle much better if it sent the Key Up/Down events.

ObjC.import("Cocoa");

function key(aiKeyCode, aiDelay)
{
var source = $.CGEventSourceCreate($.kCGEventSourceStateCombinedSessionState),
keyDown = $.CGEventCreateKeyboardEvent(source, aiKeyCode, true),
keyUp = $.CGEventCreateKeyboardEvent(source, aiKeyCode, false);
$.CGEventPost($.kCGAnnotatedSessionEventTap, keyDown);
delay(aiDelay);
$.CGEventPost($.kCGAnnotatedSessionEventTap, keyUp);
}

key(53,0.02)

Just found this thread while wanting to play Terraria, could you explain a bit more and where to put this code to lets say fix it for Terraria?

The way i did it:
Open "Script Editor" app. Select Javascript at the top. paste the code. Save the file in some scripts directory you make. Then in "BTT configuration" select "keyboard shortcuts". create a shortcut for the escape key. add the action "run apple script (async in background)". then select "Source Type: Apple script from SCPT file". Then use "Choose Apple Script File" to pick the file you saved. Alternatively...

Another way would be to select "Source Type: Java Script" and just paste the code in the box. That way is easier, but you have to copy the code for any game that has the same problem. It may or may not be more efficient that way though. The first time you use a script(press escape) it may have a bit of delay if it needs to load the script engine. but i created many scripts this way to run when pressing extra mouse buttons for shortcuts, once one loads, afterwards the mouse buttons seem to have no delay.

hope this helps... I'm still waiting for the Terraria, Journey's End update to arrive. ;p such a long wait. =p