forked from bsiever/microbit-pxt-blehid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard.ts
217 lines (202 loc) · 6.1 KB
/
keyboard.ts
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Key Modifiers
class Modifier {
static readonly control = "\x01"
static readonly shift = "\x02"
static readonly alt = "\x03"
static readonly option = "\x03"
static readonly apple = "\x04"
static readonly windows = "\x04"
static readonly rightControl = "\x05"
static readonly rightShift = "\x06"
static readonly rightAlt = "\x07"
static readonly rightOption = "\x07"
static readonly rightApple = "\x08"
static readonly rightWindows = "\x08"
}
// Special Keys
class Key {
static readonly enter = "\x10\x28"
static readonly escape = "\x10\x29"
static readonly delete = "\x10\x2A"
static readonly tab = "\x10\x2B"
static readonly up = "\x10\x52"
static readonly down = "\x10\x51"
static readonly left = "\x10\x50"
static readonly right = "\x10\x4f"
static readonly vol_up = "\x10\x80"
static readonly vol_down = "\x10\x81"
}
//% color=#0000FF
//% icon="\uf11c"
//% block="Keyboard"
//% block.loc.de="Tastatur"
namespace keyboard {
//% blockId="keyboard service" block="bluetooth keyboard service"
//% block.loc.de="Bluetooth-Tastatur-Dienst"
//% shim=keyboard::startKeyboardService
//% weight=50
export function startKeyboardService() : void {
return
}
//% blockId="send string" block="send keys | $keys"
//% block.loc.de="Tasten senden | $keys"
//% shim=keyboard::sendString
//% weight=40
export function sendString(keys: string) : void {
return
}
//% blockID="keyboard on status change" block="on keyboard status change" advanced=true
//% block.loc.de="bei Änderung des Tastaturstatus"
//% shim=keyboard::setStatusChangeHandler
//% weight=20
export function setStatusChangeHandler(a: Action) {
return
}
//% blockId="keyboard enabled" block="keyboard enabled" advanced=true
//% block.loc.de="Tastatur aktiviert"
//% shim=keyboard::isEnabled
//% weight=10
export function isEnabled() : boolean {
return false;
}
export enum _Modifier {
//% block="control+"
//% block.loc.de="Control+"
control,
//% block="shift+"
//% block.loc.de="Shift+"
shift,
//% block="alt+"
//% block.loc.de="Alt+"
alt,
//% block="option+"
//% block.loc.de="Option+"
option,
//% block="command+"
//% block.loc.de="Command+"
apple,
//% block="windows+"
//% block.loc.de="Windows+"
windows,
//% block="right control+"
//% block.loc.de="rechts Control"
rightControl,
//% block="right shift+"
//% block.loc.de="rechts Schift+"
rightShift,
//% block="right alt+"
//% block.loc.de="rechts Alt+"
rightAlt,
//% block="right option+"
//% block.loc.de="rechts Option+"
rightOption,
//% block="right apple+"
//% block.loc.de="rechts Apple+"
rightApple,
//% block="right windows+"
//% block.loc.de="rechts Windows+"
rightWindows,
}
//% blockId="modifiers" block="%key"
//% block.loc.de="%key"
//% weight=30
export function modifiers(key : _Modifier) : string {
let mods = [
Modifier.control,
Modifier.shift,
Modifier.alt,
Modifier.option,
Modifier.apple,
Modifier.windows,
Modifier.rightControl,
Modifier.rightShift,
Modifier.rightAlt,
Modifier.rightOption,
Modifier.rightApple,
Modifier.rightWindows]
if(key>=_Modifier.control && key<=_Modifier.rightWindows)
return mods[key];
return ""
}
export enum _Key {
//% block="enter"
//% block.loc.de="Enter"
enter,
//% block="escape"
//% block.loc.de="Escape"
escape,
//% block="delete"
//% block.loc.de="Löschen"
delete,
//% block="tab"
//% block.loc.de="Tab"
tab,
//% block="up"
//% block.loc.de="hoch"
up,
//% block="down"
//% block.loc.de="runter"
down,
//% block="left"
//% block.loc.de="links"
left,
//% block="right"
//% block.loc.de="rechts"
right,
//% block="volume up"
//% block.loc.de="Lautstärke hoch"
vol_up,
//% block="volume down"
//% block.loc.de="Lautstärke runter"
vol_down,
}
//% blockId="key_conv" block="%key"
//% block.loc.de="%key"
//% weight=20
export function keys(key : _Key) : string {
let keys = [
Key.enter,
Key.escape,
Key.delete,
Key.tab,
Key.up,
Key.down,
Key.left,
Key.right,
Key.vol_up,
Key.vol_down
]
if(key>=_Key.enter && key<=_Key.vol_down)
return keys[key];
return "";
}
//% block="raw scancode | %code" advanced=true
//% block.loc.de="roher Scancode | %code"
//% code.min=0 code.max=255
//% weight=30
export function rawScancode(code: number) {
return "\x10"+String.fromCharCode(code)
}
//% blockId="send simultaneous keys" block="send simultaneous keys $keys || hold keys $hold" advanced=true
//% block.loc.de="Gleichzeitige Tasten senden $keys || Tasten halten $hold"
//% shim=keyboard::sendSimultaneousKeys
//% weight=50
export function sendSimultaneousKeys(keys: string, hold: boolean) : void {
return
}
//% blockId="release keys" block="release keys" advanced=true
//% block.loc.de="Tasten freigeben"
//% shim=keyboard::releaseKeys
//% weight=40
export function releaseKeys() : void {
return
}
//% block="Ereignisse pro Sekunde einstellen | %rate keys/s" advanced=true
//% block.loc.de="Tasten freigeben"
//% rate.min=5 rate.max=165 rate.defl=100
//% shim=keyboard::setEventsPerSecond
//% weight=50
export function setEventsPerSecond(rate: number) : void {
return
}
}