开发者

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

开发者 https://www.devze.com 2023-04-11 17:30 出处:网络
think user pressed two keys at same time . I want to b开发者_StackOverflowe notified of this two keys , not one .

think user pressed two keys at same time .

I want to b开发者_StackOverflowe 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消