forked from jamiebuilds/tinykeys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
145 lines (129 loc) · 2.89 KB
/
Copy pathindex.html
File metadata and controls
145 lines (129 loc) · 2.89 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>tinykeys</title>
<style>
*,
::before,
::after {
box-sizing: border-box;
}
body {
margin: 50px auto 100px;
padding: 0 20px;
max-width: 720px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}
a {
color: hsl(250 100% 50%);
font-weight: bold;
}
h1 + p {
font-size: 1.2em;
}
pre,
code,
kbd {
font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
}
li {
margin: 10px 0;
}
kbd {
padding: 2px 6px;
background: hsl(250 90% 90%);
border-radius: 8px;
}
pre {
margin: 20px 0;
padding: 20px;
background: hsl(250 90% 95%);
overflow: auto;
-webkit-overflow-scrolling: touch;
border-radius: 8px;
}
pre strong {
color: hsl(250 90% 50%);
}
pre em {
color: hsl(250 20% 50%);
font-style: normal;
}
#logs {
max-height: 400px;
overflow: auto;
}
</style>
</head>
<body>
<h1>
<code>tinykeys</code>
</h1>
<p>
A tiny (~400 B) & modern library for keybindings. See on
<a href="https://github.com/jamiebuilds/tinykeys">GitHub</a>
</p>
<pre>npm install tinykeys</pre>
<h2>Examples</h2>
<p>Try one of the following:</p>
<ul>
<li><kbd>Shift+D</kbd></li>
<li><kbd>y e e t</kbd></li>
<li>
<kbd>Control+D</kbd> (Windows/Linux) or <kbd>Command+D</kbd> (Mac)
</li>
</ul>
<pre>
import tinykeys from "tinykeys"
tinykeys(window, {
<strong>"Shift+D"</strong>: () => {
<em>alert("The 'Shift' and 'd' keys were pressed at the same time")</em>
},
<strong>"y e e t"</strong>: () => {
<em>alert("The keys 'y', 'e', 'e', and 't' were pressed in order")</em>
},
<strong>"$mod+KeyD"</strong>: () => {
<em>alert("Either 'Control+d' or 'Meta+d' were pressed")</em>
},
})
</pre>
<h2>History</h2>
<p>
Logs
<a
href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key"
><code>KeyboardEvent.key</code></a
>
and
<a
href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values"
><code>KeyboardEvent.code</code></a
>
used by this library
</p>
<pre id="logs">(start typing)</pre>
<script src="./index.tsx"></script>
<script>
let logsElement = document.querySelector("#logs")
let logs = []
window.addEventListener("keydown", event => {
logs.unshift({
key: event.key,
code: event.code,
modifier: event.getModifierState(event.key),
})
logsElement.innerText = logs
.map(log => {
return (
`key: "${log.key}", code: "${log.code}"` +
(log.modifier ? ` (modifier)` : ``)
)
})
.join("\n")
})
</script>
</body>
</html>