如何检测按钮是否被按下?
how to detect if a button is being pressed?
你看,我不想检测按钮是否被点击,而是在按钮被按下时发出命令(在我的例子中,就是让玩家移动)
如果你想做某事(移动你的播放器)当使用鼠标按下(向下)按钮时,你可以使用 mousedown
事件 (https://developer.mozilla.org/en-US/docs/Web/API/Element/mousedown_event). It is fired the moment the (mouse) button is initially pressed. This is the moment when you can start moving your player. Then you will want to stop moving your player when the mouseup
event is fired (https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseup_event).
你看,我不想检测按钮是否被点击,而是在按钮被按下时发出命令(在我的例子中,就是让玩家移动)
如果你想做某事(移动你的播放器)当使用鼠标按下(向下)按钮时,你可以使用 mousedown
事件 (https://developer.mozilla.org/en-US/docs/Web/API/Element/mousedown_event). It is fired the moment the (mouse) button is initially pressed. This is the moment when you can start moving your player. Then you will want to stop moving your player when the mouseup
event is fired (https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseup_event).