-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
98 lines (84 loc) · 2.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<title>RT Control</title>
<script type="text/javascript" src="static/javascript/jquery-1.2.6.min.js"></script>
</head>
<body>
<div id="dir">{{value}}</div>
<form>
<fieldset>
<label for="target">Drive Car (WASD):</label>
<input id="target" type="text">
</fieldset>
</form>
<form>
<input type="radio" name="robot" id="rt" value="rt" checked>Control RT
<br>
<input type="radio" name="robot" id="ab" value="anthonybot">Control Anthonybot
</form>
<script>
var previousCharacer = 0;
var totalKeyValue = 0;
var keyValues = new Map();
keyValues.set("w", 1);
keyValues.set("a", 10);
keyValues.set("s", 100);
keyValues.set("d", 1000);
var keysPressed = new Map();
keysPressed.set("w", false);
keysPressed.set("s", false);
keysPressed.set("a", false);
keysPressed.set("d", false);
$( "#target" ).keypress(function( event)
{
//console.log("now pressing " + String.fromCharCode(event.which) + "(" + event.which+")");
sendKey(event.which, true);
});
$( "#target" ).keyup(function()
{
//console.log("now releasing " + String.fromCharCode(event.which) + "(" + event.which+")");
sendKey(event.which, false);
});
function sendKey(numCode, pressed)
{
$('input[type=text], textarea').val('');
var charCode = String.fromCharCode(numCode).toLowerCase();
var value = keyValues.get(charCode);
if (value == undefined)
return;
if (pressed)
{
if (keysPressed.get(charCode) == true)
return;
keysPressed.set(charCode, true);
}
else
{
keysPressed.set(charCode, false);
value *= -1;
}
totalKeyValue += value;
var instructionString;
if (totalKeyValue == 0)
instructionString = '0000';
else if (totalKeyValue < 10 && totalKeyValue > 0)
instructionString = '0001';
else if (totalKeyValue < 100)
instructionString = '00' + totalKeyValue;
else if (totalKeyValue < 1000)
instructionString = '0' + totalKeyValue;
else if (totalKeyValue >= 1000)
instructionString = totalKeyValue;
console.log(instructionString)
document.getElementById("dir").innerHTML = instructionString;
$.ajax(
{
url: "/rt",
type: "post", //send it through get method
data:{value:instructionString},
});
}
</script>
</body>
</html>