JavaScript allows you to use a keyboard to control the movement of people and javascript instances.
In fact, this example uses the js core time, the keyboard event onkeydown, and the periodical execution event setInterval.
Effect
When you press a key on the keyboard, the characters in the webpage can be used to control the movement.
Steps
I. Reserved key values:
W: Up
S: Down
A: left
D: Right
Space: Stop
2. After the key value is reserved, You need to capture the key event and determine which key the user presses?
You can use onkeydown to capture Keyboard Events.
You can use event. keyCode to obtain the key-value code.
3. Use setInterval to replace the image
The picture is replaced to achieve the task moving Effect
Note that the clearInterval clearing cycle is used for execution.
Sample Code:
<Html>
Javascript code for keyboard control
<Style>
Tr. highlight {background: # 000006b; color: white ;}
</Style>
<Table border = "1" width = "70%" id = "ice">
<Tr>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
</Tr>
<Tr>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
</Tr>
<Tr>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
</Tr>
<Tr>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
</Tr>
<Tr>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
<Td> <input type = 'text'> </td>
</Tr>
</Table>
<Script ...... remaining full text>
ActionScript30 keyboard control
I didn't see your purpose in the code, but according to your question: the keyboard controls the movement of people. I understood it as controlling the movement of "instances" through the upper, lower, and lower arrows of the keyboard, my idea is: create two kinds of event listening for the instance, one is to press the mouse, the other is to press the keyboard, the keyboard is to play the number of pixels that the target moves, if the keyboard is to press, then, you can add an Event to this or others. The enter_frame event is executed every time a frame is exceeded. This event is mainly used to move the instance continuously when the keyboard direction key is long and pressed.