Reputation: 8306
I am handling keydown
which provides a KeyboardEvent
on a webpage. I want to only do something if the user pressed a specific letter without holding any modifiers. However, I cannot figure out how to check for this properly.
I can manually check that KeyboardEvent.altKey
, KeyboardEvent.ctrlKey
, KeyboardEvent.metaKey
, and KeyboardEvent.shiftKey
are all false
. (And I will immediately exit my handler if KeyboardEvent.isComposing
is set. That is not exactly a modifier key, but I also do not want to interfere with composition incorrectly.)
However, I think I am missing some guidance here. Is this the exhaustive list of properties to check? What if new keyboards come out with a new modifier key that is somehow super popular and adopted by everyone and even the Web API adds another property for it in the future?
Is there a property which has a bitmask of the modifier keys so I can check for a specific combination of modifiers easily while also being able to easily check that no modifiers are pressed by comparing it to 0
? This would match the problem I am trying to solve much better than the split out properties.
Upvotes: 0
Views: 32