-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
58 lines (58 loc) · 1.68 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Key modifiers</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/0.5.0/modern-normalize.min.css">
</head>
<body>
<style>
form {
margin-bottom: 1rem;
}
#root > div {
border: 1px solid #aff;
padding: 1rem;
}
</style>
<div id="root">
<form @keyup="handleKeyup">
<div>
<label for="inp">Press <code>ESC</code> or <code>w</code> key</label>
<input type="text" id="inp" >
</div>
</form>
<form @keyup="handleBody">
<div>
<label for="inp2">Press <code>any</code> key</label>
<input type="text" id="inp2" ref="inputElement">
</div>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script>
new Vue({
el: '#root',
methods: {
handleKeyup(event) {
console.log(event);
if(event.keyCode === 27 || event.keyCode === 87) { // ESC
console.log('YEP');
} else {
console.log('NOPE');
}
},
handleBody(event) {
if(event.code === "Space") {
this.$refs.inputElement.parentElement.insertAdjacentHTML('beforeend', `<b style="display: block;">You pressed key:</b> ${event.code}`);
} else {
this.$refs.inputElement.parentElement.insertAdjacentHTML('beforeend', `<b style="display: block;">You pressed key:</b> ${event.key}`);
}
}
}
})
</script>
</body>
</html>