一个完整的鼠标与键盘事件演示代码如下:
Demonstrates HTML5 Canvas mouse events, obtains mouse coordinates on the Canvas object, and demonstrates keyboard events to control the movement of objects on the Canvas through the keyboard.
The Canvas object supports all JavaScript mouse events, including mouse click (MouseClick), mouse press (Mouse Down), mouse lift (Mouse Up), mouse move (Mouse Move). Add mouse events to Canvas There are two ways, one way is to complete it through API:
Press W, A, S, D keys to move