-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
keyboard.cpp
82 lines (67 loc) · 1.83 KB
/
keyboard.cpp
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
/**
* Bill Siever
* 2021-11-20 Initial Version
*
* Development environment specifics:
* Written in Microsoft PXT
*
* This code is released under the [MIT License](http://opensource.org/licenses/MIT).
* Please review the LICENSE.md file included with this example. If you have any questions
* or concerns with licensing, please contact [email protected].
* Distributed as-is; no warranty is given.
*/
#include "pxt.h"
#include "MicroBit.h"
#include "KeyboardReporter.h"
#include "HIDService.h"
#include "debug.h"
static KeyboardReporter *reporter = NULL;
using namespace pxt;
namespace keyboard {
bool isInitialized() {
if(reporter == NULL) {
uBit.display.scroll("Keyboard not started");
return false;
} else {
return true;
}
}
//%
void startKeyboardService() {
if(reporter == NULL) {
reporter = KeyboardReporter::getInstance();
}
}
//%
void sendString(String keys) {
if(!isInitialized()) return;
reporter->sendString(keys->ascii.data, keys->ascii.length);
}
//%
bool isEnabled() {
DEBUG("Keyboard isEnabled\n");
return reporter ? reporter->isEnabled() : false;
}
//%
void setStatusChangeHandler(Action action) {
if(!reporter) return;
reporter->setStatusChangeHandler(action);
}
//%
void sendSimultaneousKeys(String keys, bool hold) {
if(!isInitialized()) return;
reporter->sendSimultaneousKeys(keys->ascii.data, keys->ascii.length);
if(!hold) {
reporter->sendScanCode(0,0);
}
}
//%
void releaseKeys() {
if(!isInitialized()) return;
reporter->sendScanCode(0,0);
}
//%
void setEventsPerSecond(uint32_t rate) {
HIDService::setEventsPerSecond(rate);
}
}