Detect if modifier key (Option) is held in Real JavaScript?

Hi there,

As topic; I've searched around and couldn't find anything about this. Using the URL Automation (for opening links in different browsers), I would like to check, in the JavaScript code, to see if the user is holding the Option key after clicking the URL, and, if so, I'd open that link in a specific browser.

Could you please advise on how to check for those modifiers keys from within JavaScript code? I find it very difficult to have complete documentation about what can be done, as this Real JavaScript is not running in a browser, so I have zero idea how to reference anything I need in macOS from it (and haven't found anything in the BTT documentation).

Thanks in advance!

the easiest would be to query the BTT variable currently_pressed_keyboard_keys like this:

let pressedKeys = await get_string_variable({variable_name:'currently_pressed_keyboard_keys'})
if(pressedKeys.contains('56,')) {
   // option is pressed
}

You can see these variables when configuring an advanced trigger condition.

If opt is pressed it would return a string that contains "56,"

Tip for debugging the real javascript: you can see logs etc. in Safari:

Awesome Andreas; thanks for your incredible quick response! I don't know how you do it; answering in minutes, try to get to most of the hundreds of questions, develop new features on the fly... you are amazing man. Probably never sleep!

Please never sell out to a shady company like "good old Ben" from the Bartender thread :smiley: