-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkeyConfig.html
More file actions
148 lines (136 loc) · 3.79 KB
/
keyConfig.html
File metadata and controls
148 lines (136 loc) · 3.79 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<html>
<head>
<style>
.buttonConfig {
position: absolute;
height: 50px;
width: 50px;
background-color: #888;
text-align: center;
display: inline-block;
vertical-align: middle;
line-height: 50px;
font-weight: bold;
font-size: 20px;
color: #333;
}
#back {
left: 60px;
top: 60px;
}
#forward {
left: 60px;
}
#left {
top: 60px;
}
#right {
top: 60px;
left: 112px;
}
#reset {
top: 164px;
}
#chat {
top: 164px;
left: 60px;
}
#inventory {
top: 164px;
left: 112px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="./js/jquery.color.min.js"></script>
<script>
var buttons = {
forward: 87,
left: 65,
back: 83,
right: 68,
reset: 82,
chat: 84,
inventory: 73
}
;
var keyAvalible = false;
$(function() {
$(".buttonConfig").mouseover(function(e) {
$(document).on("keydown", function(f) {
keyAvalible = true;
for (var i in buttons) {
if (buttons[i] == f.which){ keyAvalible = false;console.log("button used");}
}
if (keyAvalible) {
switch(f.which)
{
case 37:
$("#" + e.target.id).html("←");
break;
case 38:
$("#" + e.target.id).html("↑");
break;
case 39:
$("#" + e.target.id).html("→");
break;
case 40:
$("#" + e.target.id).html("↓");
break;
case 17:
$("#" + e.target.id).text("ctrl");
break;
case 16:
$("#" + e.target.id).text("shift");
break;
case 32:
$("#" + e.target.id).text("space");
break;
case 20:
$("#" + e.target.id).text("caps");
break;
case 9:
$("#" + e.target.id).text("tab");
break;
case 13:
$("#" + e.target.id).text("enter");
break;
case 18:
$("#" + e.target.id).text("alt");
break;
case 93:
$("#" + e.target.id).text("menu");
break;
case 91:
$("#" + e.target.id).text("win key");
break;
default:
$("#" + e.target.id).text(String.fromCharCode(f.which).toLowerCase());
}
buttons[e.target.id] = f.which;
}else{
$("#" + e.target.id).animate({backgroundColor:"#AC3333"},'fast');
setTimeout(function(){
$("#" + e.target.id).animate({backgroundColor:"#888"},'slow');
},1000);
}
$("#data").text(JSON.stringify(buttons));
});
});
$(".buttonConfig").mouseleave(function(e) {
$(document).off("keydown");
});
}
);
</script>
</head>
<body>
<div class="buttonConfig" id="forward">w</div>
<div class="buttonConfig" id="back">s</div>
<div class="buttonConfig" id="left">a</div>
<div class="buttonConfig" id="right">d</div>
<div class="buttonConfig" id="reset">r</div>
<div class="buttonConfig" id="chat">t</div>
<div class="buttonConfig" id="inventory">i</div>
<div id="data" hidden> </div>
</body>
</html>