1 < Body >
2 < Div ID = " Man " Style = " Position: absolute; width: 50px; Height: 40px; top: 200px; left: 200px; Background: red " > </ Div >
3 < Button onclick = " Alert (keycache. length) " > Ask </ Button >
4 </ Body >
5 < Script >
6 VaR Keycache = [];
7 VaR Iscache = False ;
8 VaR Cachenum = 0 ;
9
10 Document. onkeydown = Insertkey;
11 Document. onkeyup = Function () {If(!Iscache&&Event. keycode> =37&&Event. keycode<=40) Keycache. Length= 0;}
12
13 Function Insertkey () {
14 VaR KC = Event. keycode;
15 If (KC > = 37 && KC <= 40 ) {
16 If (KC ! = Keycache [keycache. Length - 1 ]) {
17 Keycache. Length = 0 ;
18 Keycache. Push (KC, KC) // Ensures smooth multi-injection of 6
19 Iscache = True ;
20 }
21 Keycache. Push (KC );
22 }
23 }
24
25 Window. setinterval ( " Writecache () " , 50 );
26
27 Function Writecache () {
28 If (Keycache. Length = 0 ) Return ;
29
30 VaR KC = Keycache. Shift ();
31
32 Switch (KC) {
33 Case 37 : Man. style. Left = Parseint (man. style. Left) - 5 ; Break ;
34 Case 38 : Man. style. Top = Parseint (man. style. Top) - 5 ; Break ;
35 Case 39 : Man. style. Left = Parseint (man. style. Left) + 5 ; Break ;
36 Case 40 : Man. style. Top = Parseint (man. style. Top) + 5 ; Break ;
37 }
38
39 If (Iscache) cachenum ++ ;
40 If (Cachenum = 5 ) {
41Iscache= False;
42Cachenum= 0;
43}
44 }
45 </ Script >