简体   繁体   中英

how to track two keyboard key when they are down at same time

think user pressed two keys at same time .

I want to be notified of this two keys , not one .

like Up + Left

how can I find out this ?

you should register handlers for the keyup and keydown events.

for each key involved in your key combination, you store a flag which tells if the key is up or down. each time you receive a keydown event for one of those keys, you set the flags, each time you receive a keyup event, you reset the flag (set it back to 0).

when all the flags are set, it means that all the keys for the combination are pressed at the same time, you can then call a function of your choice to react on this event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM