Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        3年前关闭。
                                                                                            
                
        
所以我正在做一个游戏,我希望能够为角色添加控件。因此,我希望游戏能够检测用户是否按下了按键W。

    if(W is pressed){
     Do something
    }

最佳答案

您可以为keydown添加一个EventListener并检查event

document.addEventListener('keydown', function(e){
   if(e.key === 'w')
   console.log('hei w')
})

关于javascript - 如何判断是否按下了W键,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39133342/

10-12 02:28