-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeys.html
executable file
·62 lines (62 loc) · 1.34 KB
/
keys.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
<html>
<head>
<title>Key presses</title>
<style>
input {
width: 500px;
}
</style>
<script>
'use strict';
function translate(key) {
if (key === ' ') {
return 'Space';
}
if (key.length === 1) {
return key.toUpperCase();
}
return key;
}
function keydown(event) {
event.preventDefault()
var key = translate(event.key);
var text = event.target.value;
var words = text.split(" ");
var i;
for (i in words) {
var w = words[i];
if (w === key) {
return false;
}
}
if (text === "") {
text = key;
} else {
text = text + " " + key
}
event.target.value = text
return false;
}
function keyup(event) {
var key = translate(event.key);
var text = event.target.value;
var words = text.split(" ");
var result = [];
var i;
for (i in words) {
var w = words[i];
if (w !== "" && w !== key) {
result.push(w);
}
}
event.target.value = result.join(" ");
return false;
}
</script>
</head>
<body onload="document.getElementById('input').focus()">
<h1>Press some keys!</h1>
<p>Ensure JavaScript is enabled and that the focus is in the input box below, then you can test your keys and key combinations.</p>
<input id="input" onkeydown="keydown(event)" onkeyup="keyup(event)" />
</body>
</html>