Arielo
Arielo

Reputation: 231

How to handle alt+p keyboardEvent on macOS browsers

I'ld like to listen the following keyboardEvent : alt + p

if (event.altKey && event.key === "p") {

  doThis(stuff)

}

Problem is that in OSX (alt+p) === "π"

so I wrote this ugly condition for Mac OSX users

 if (
      (event.altKey && event.key === "π") ||
      (event.altKey && event.key === "p")
    ) {

       doThis(stuff)

}

It works AND it's ugly =D

So if anyone has a better way to handle this please give me a hint !

USEFULL REMINDER: keyCode and charCode are DEPRECATED

Upvotes: 2

Views: 797

Answers (1)

Arielo
Arielo

Reputation: 231

I figured out that 'keyCode' and 'charCode' are deprecated & have been replaced by '.code' & '.key'. so event.key is just fine =D

Upvotes: 1

Related Questions