The MouseEvent
class has the properties altKey
, ctrlKey
and shiftKey
that I can use to determine if a modifier key (namely, Alt, Ctrl and Shift) was held down when the event occurred.
But I want to determine if Space key is held down during a MouseEvent. How can I do this?
As @Timofei Davydik suggested, I do this the "manual" way by listening to
KeyboardEvent
and set a flag to indicate the state of space key being held. Then I just use the value of this flag in the listener ofMouseEvent
. The code is somewhat like this (you can add any other key that you need to watch):The KeyboardEvent listeners: