Is there something like ScriptUI's "keyboardState" in UXP?

In my old Extendscript/CEP Panels I always used “keyboardState” to add a secondary behavior to my buttons. For example, when a modifier key like shift is pressed while clicking on the button a different function is called:

} else {

Does anybody know if there is something similar in UXP? Thanks!

Check Adobe’s Kitchen-sink plugin - it has an example (Alt and Shift are detected, but Ctrl isn’t for some reason)

1 Like

Thanks for pointing that out. Unfortunately I have no Idea how I can implement that in a similar way as I did with CEP. Any chance you can point me in the right direction?

Oh and by the way, ctrl and meta (command on mac) are also detected on my machine (PS 23.0.0) …?!

I still haven’t figured out how I can adapt that code from the kitchensink example which @Karmalakas pointed out. Maybe anyone with some tipps? :slight_smile:

I’m a vanilla JS coder only, but here’s what I use that seems to work:

document.getElementById("yourButton").addEventListener("click", event => {
    if (event.ctrlKey || event.metaKey) {doSomething();} 
    else {doSomethingElse();}

“event.ctrlKey” catches Windows
“event.metaKey” catches Mac

1 Like

Hi AnthonyK, thank you so much! It works perfectly. I simply messed up the syntax here, so all my tries failed. Thanks for pointing me in the right direction :slight_smile: