/
index.html
191 lines (161 loc) · 5.36 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!doctype html>
<meta charset="utf-8" />
<title>Custom Element: <key-input></title>
<style>
code {
background-color: #ddd;
padding: 4px;
}
dt {
font-weight: bold;
margin-top: 1em;
}
output {
font-family: monospace;
font-size: 1.2em;
font-weight: bold;
}
</style>
<script type="module">
import * as ki from "./js/key-input-registerer.js";
ki.register();
</script>
<h1>Custom Element: <code>key-input</code></h1>
<p>Custom elements to input key press events.</p>
<p>
See
<a
href="https://github.com/kui/key-input-elements/blob/master/docs/index.html"
>this HTML source</a
>.
</p>
<p>
<a href="https://github.com/kui/key-input-elements">GitHub repository </a>
</p>
<h2>Usage</h2>
<dl>
<dt>Simple Usage: <input is="key-input" /></dt>
<dd>Just <code><input is="key-input" /></code></dd>
<dt><code>raw-mod</code> Bool Attribute: <input is="key-input" raw-mod /></dt>
<dd>Treat modifier keys as normal keys.</dd>
<dt>
<code>multiple</code> Bool Attribute: <input is="key-input" multiple />
</dt>
<dd>Allow multiple keys.</dd>
<dt>
<code>multiple</code> and <code>raw-mod</code>:
<input is="key-input" multiple raw-mod />
</dt>
<dd>
This is the useful combination when you want to detect an event that
distinguish <code>ShiftLeft</code> and <code>ShiftRight</code>.
</dd>
<dt>
<code>ignore</code> attribute:
<input is="key-input" ignore="( |^)(Tab|KeyA)$" />
</dt>
<dd>
Ignore provided pattern. This example ignores <code>Tab</code> and
<code>KeyA</code>.
</dd>
</dl>
<h2>Matching KeyboardEvent</h2>
<p>This package provide classes to match <code>KeyboardEvent</code>.</p>
<h3>Match with the Latest KeyboardEvent: <code>KeyInputMatcher</code></h3>
<p>
<code>KeyInputMatcher</code> is a class to match the latest
<code>KeyboardEvent</code> with a provided pattern.
</p>
<p>
Press any key in the following input element. The
<code>KeyInputMatcher</code> is built with
<code>Shift + KeyA + KeyS + KeyD</code>. The result of matching with the input
element is displayed in the following output elements. The result is
<code>true</code> if the input element matches with each condition.
</p>
<script type="module">
import { KeyInputMatcher } from "./js/event-matchers/key-input.js";
window.addEventListener("DOMContentLoaded", () => {
console.log("Setting up 'key input matcher' example");
const matcher = KeyInputMatcher.parse("Shift + KeyA + KeyS + KeyD");
keyinput1.addEventListener("keydown", (e) => {
const m = matcher.keydown(e);
display1.value = m.match({ historySensitive: "ignore" });
display2.value = m.match({ historySensitive: "orderInsensitive" });
display3.value = m.match({ historySensitive: "orderSensitive" });
});
keyinput1.addEventListener("keyup", (e) => {
matcher.keyup(e);
});
});
</script>
<p>
<code>key-input</code> element:
<input is="key-input" id="keyinput1" multiple />
</p>
<dl>
<dt><code>historySensitive=ignore</code></dt>
<dd>
result= <output id="display1"></output><br />
Display <code>true</code> if you input <code>Shift + KeyD</code>
</dd>
<dt><code>historySensitive=orderInsensitive</code> (default)</dt>
<dd>
result= <output id="display2"></output><br />
Display <code>true</code> if you input <code>KeyD</code> with holding down
any <code>Shift</code> keys, <code>KeyA</code> and <code>KeyS</code>.
</dd>
<dt><code>historySensitive=orderSensitive</code></dt>
<dd>
result= <output id="display3"></output><br />
Display <code>true</code> if you input <code>KeyD</code> with holding down
any <code>Shift</code> keys, <code>KeyA</code> and <code>KeyS</code> with
the order.
</dd>
</dl>
<h3>Match with Holding Keys: <code>KeyHoldMatcher</code></h3>
<p>
<code>KeyHoldMatcher</code> is a class to match the history of
<code>KeyboardEvent</code> with a provided pattern.
</p>
<p>
Press any key in the following input element. The
<code>KeyHoldMatcher</code> is built with
<code>Shift + ShiftLeft + KeyA + KeyS</code>. The result of matching with the
input element is displayed in the following output elements. The result is
<code>true</code> if the input element matches with each condition.
</p>
<script type="module">
import { KeyHoldMatcher } from "./js/event-matchers/key-hold.js";
window.addEventListener("DOMContentLoaded", () => {
console.log("Setting up 'hold matcher' example");
const matcher = KeyHoldMatcher.parse("Shift + ShiftLeft + KeyA + KeyS");
keyinput2.addEventListener("keydown", (e) => {
const m = matcher.keydown(e);
display4.value = m.match();
display5.value = m.match({ rawMod: true });
});
keyinput2.addEventListener("keyup", (e) => {
const m = matcher.keyup(e);
display4.value = m.match();
display5.value = m.match({ rawMod: true });
});
});
</script>
<p>
<code>key-input</code> element:
<input is="key-input" id="keyinput2" multiple raw-mod />
</p>
<dl>
<dt><code>rawMod=false</code> (default)</dt>
<dd>
result= <output id="display4"></output><br />
Display <code>true</code> if you hold <code>KeyA + KeyS</code> with any
<code>Shift</code> keys.
</dd>
<dt><code>rawMod=true</code></dt>
<dd>
result= <output id="display5"></output><br />
Display <code>true</code> if you hold <code>ShiftLeft + KeyA + KeyS</code>.
</dd>
</dl>