-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard_functional.cpp
64 lines (56 loc) · 1.54 KB
/
keyboard_functional.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
#include "keyboard_functional.h"
using namespace Z;
/*
Returns the keycode for a functionkey
*/
Keycode Z::function_keycode(const FunctionKey modifier)
{
return modifier | static_cast<uint16_t>(KeySignature::FUNCTION);
}
/*
Returns the function key that corresponds to a specific keycode
*/
Z::FunctionKey Z::function_from_keycode(const Keycode key)
{
if((get_key_type(key) != KeyType::FN) || key >= FN_AMOUNT)
{
exception("Key passed to modifier_from_keycode is not a valid modifier");
}
return (FunctionKey) key;
}
/*
Returns the type of a key
*/
Z::KeyType Z::get_key_type(const Keycode key)
{
uint16_t signature = key & KEYTYPE_MASK;
switch(signature)
{
case static_cast<uint16_t>(KeySignature::FUNCTION):
return KeyType::FN;
case static_cast<uint16_t>(KeySignature::MODIFIER):
return KeyType::MODIFIER;
case static_cast<uint16_t>(KeySignature::MEDIA):
return KeyType::MEDIA;
case static_cast<uint16_t>(KeySignature::SYSTEM):
return KeyType::SYSTEM;
case static_cast<uint16_t>(KeySignature::STANDARD):
return KeyType::STANDARD;
default:
DEBUG_PRINT("Unrecognised key signature ");
DEBUG_PRINTLN(signature);
return KeyType::UNRECOGNISED;
}
}
/*
Initializes a list of modifiers
*/
Z::FunctionKeyList Z::init_function_key_list()
{
auto result = FunctionKeyList();
for(uint8_t i = 0; i < FN_AMOUNT; i++)
{
result.push(false);
}
return result;
}