forked from kshoji/pxt-bluetooth-keyboard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyboard.cpp
43 lines (40 loc) · 961 Bytes
/
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
#include "pxt.h"
#include "BluetoothKeyboardService.h"
using namespace pxt;
/**
* A set of functions to send keyboard commands over Bluetooth
*/
namespace bluetooth
{
BluetoothKeyboardService *pKeyboardInstance = nullptr;
BluetoothKeyboardService *getKeyboard()
{
if (pKeyboardInstance == nullptr)
{
pKeyboardInstance = new BluetoothKeyboardService(uBit.ble);
}
return pKeyboardInstance;
}
//%
void keyboardSendOneKeyCode(Modifier modifier, uint8_t keyCode)
{
BluetoothKeyboardService *pKeyboard = getKeyboard();
pKeyboard->sendKeyCode(modifier, keyCode);
}
//%
uint8_t keyboardGetKeyCode(uint8_t character)
{
BluetoothKeyboardService *pKeyboard = getKeyboard();
return pKeyboard->getKeyCode(character);
}
//%
void keyboardSendText(StringData *data)
{
BluetoothKeyboardService *pKeyboard = getKeyboard();
ManagedString buf(data);
if (buf.length() > 0)
{
pKeyboard->sendString(buf);
}
}
}