简体   繁体   中英

How to not allow two keys to be pressed in a row in JavaScript?

Im making a snake game and need some code to not allow the same key to be pressed in a row. So for example if 'w' is pressed, it wont be able to be pressed again until another key is pressed. Anyone now the simplest way to achieve this? Thanks

当您收到按键事件时,保存上次按下的按键并检查新按键是否相同,然后从函数中返回。

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