Shortcut : Alt + pressing a plugin's button

Hi everybody

could you please suggest me how could I catch when the user press the Alt key on the keyboard while pressing a button of my plugin ?

Thanks
Daniele

You need to check it in the click event. Something like this in React (you can easily change it to normal JS)

<button onClick={ (event) => {
     event.preventDefault() ;
     if (event.altKey) {
       // Alt is pressed
     }
   } }
>Click me</button>

Thnk you @Karmalakas , you are always so kind and helpful !

image
Where would I input an alt key in this?

I want my script to hideAll when alt click is pressed.

I’m sorry but I’m not able to help in this case

you don’t setup the event to use with alt, but instead, in function, check if the event occured with altKey selected

Rather than call your function directly in the event listener, call it conditionally within an anonymous function instead.

// Listen for click event with anonymous function callback, passing in the event as a parameter 
.addEventListener("click", (event) => {
  // Conditional logic
  if (somethingIsTrue) {
    // Any condition code, e.g.:
    aFunctionCall();
  }
})
1 Like

As always, you’re awesome. Thanks man!

1 Like