summaryrefslogtreecommitdiff
path: root/src/input_common/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/drivers')
-rw-r--r--src/input_common/drivers/keyboard.cpp52
-rw-r--r--src/input_common/drivers/keyboard.h14
2 files changed, 52 insertions, 14 deletions
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp
index 328fe1ac1..23b0c0ccf 100644
--- a/src/input_common/drivers/keyboard.cpp
+++ b/src/input_common/drivers/keyboard.cpp
@@ -13,15 +13,26 @@ constexpr PadIdentifier key_identifier = {
13 .port = 0, 13 .port = 0,
14 .pad = 0, 14 .pad = 0,
15}; 15};
16constexpr PadIdentifier modifier_identifier = { 16constexpr PadIdentifier keyboard_key_identifier = {
17 .guid = Common::UUID{Common::INVALID_UUID}, 17 .guid = Common::UUID{Common::INVALID_UUID},
18 .port = 0, 18 .port = 1,
19 .pad = 0,
20};
21constexpr PadIdentifier keyboard_modifier_identifier = {
22 .guid = Common::UUID{Common::INVALID_UUID},
23 .port = 1,
19 .pad = 1, 24 .pad = 1,
20}; 25};
21 26
22Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { 27Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) {
28 // Keyboard is broken into 3 diferent sets:
29 // key: Unfiltered intended for controllers.
30 // keyboard_key: Allows only Settings::NativeKeyboard::Keys intended for keyboard emulation.
31 // keyboard_modifier: Allows only Settings::NativeKeyboard::Modifiers intended for keyboard
32 // emulation.
23 PreSetController(key_identifier); 33 PreSetController(key_identifier);
24 PreSetController(modifier_identifier); 34 PreSetController(keyboard_key_identifier);
35 PreSetController(keyboard_modifier_identifier);
25} 36}
26 37
27void Keyboard::PressKey(int key_code) { 38void Keyboard::PressKey(int key_code) {
@@ -32,35 +43,50 @@ void Keyboard::ReleaseKey(int key_code) {
32 SetButton(key_identifier, key_code, false); 43 SetButton(key_identifier, key_code, false);
33} 44}
34 45
35void Keyboard::SetModifiers(int key_modifiers) { 46void Keyboard::PressKeyboardKey(int key_index) {
47 if (key_index == Settings::NativeKeyboard::None) {
48 return;
49 }
50 SetButton(keyboard_key_identifier, key_index, true);
51}
52
53void Keyboard::ReleaseKeyboardKey(int key_index) {
54 if (key_index == Settings::NativeKeyboard::None) {
55 return;
56 }
57 SetButton(keyboard_key_identifier, key_index, false);
58}
59
60void Keyboard::SetKeyboardModifiers(int key_modifiers) {
36 for (int i = 0; i < 32; ++i) { 61 for (int i = 0; i < 32; ++i) {
37 bool key_value = ((key_modifiers >> i) & 0x1) != 0; 62 bool key_value = ((key_modifiers >> i) & 0x1) != 0;
38 SetButton(modifier_identifier, i, key_value); 63 SetButton(keyboard_modifier_identifier, i, key_value);
39 // Use the modifier to press the key button equivalent 64 // Use the modifier to press the key button equivalent
40 switch (i) { 65 switch (i) {
41 case Settings::NativeKeyboard::LeftControl: 66 case Settings::NativeKeyboard::LeftControl:
42 SetButton(key_identifier, Settings::NativeKeyboard::LeftControlKey, key_value); 67 SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftControlKey, key_value);
43 break; 68 break;
44 case Settings::NativeKeyboard::LeftShift: 69 case Settings::NativeKeyboard::LeftShift:
45 SetButton(key_identifier, Settings::NativeKeyboard::LeftShiftKey, key_value); 70 SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftShiftKey, key_value);
46 break; 71 break;
47 case Settings::NativeKeyboard::LeftAlt: 72 case Settings::NativeKeyboard::LeftAlt:
48 SetButton(key_identifier, Settings::NativeKeyboard::LeftAltKey, key_value); 73 SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftAltKey, key_value);
49 break; 74 break;
50 case Settings::NativeKeyboard::LeftMeta: 75 case Settings::NativeKeyboard::LeftMeta:
51 SetButton(key_identifier, Settings::NativeKeyboard::LeftMetaKey, key_value); 76 SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftMetaKey, key_value);
52 break; 77 break;
53 case Settings::NativeKeyboard::RightControl: 78 case Settings::NativeKeyboard::RightControl:
54 SetButton(key_identifier, Settings::NativeKeyboard::RightControlKey, key_value); 79 SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightControlKey,
80 key_value);
55 break; 81 break;
56 case Settings::NativeKeyboard::RightShift: 82 case Settings::NativeKeyboard::RightShift:
57 SetButton(key_identifier, Settings::NativeKeyboard::RightShiftKey, key_value); 83 SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightShiftKey, key_value);
58 break; 84 break;
59 case Settings::NativeKeyboard::RightAlt: 85 case Settings::NativeKeyboard::RightAlt:
60 SetButton(key_identifier, Settings::NativeKeyboard::RightAltKey, key_value); 86 SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightAltKey, key_value);
61 break; 87 break;
62 case Settings::NativeKeyboard::RightMeta: 88 case Settings::NativeKeyboard::RightMeta:
63 SetButton(key_identifier, Settings::NativeKeyboard::RightMetaKey, key_value); 89 SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightMetaKey, key_value);
64 break; 90 break;
65 default: 91 default:
66 // Other modifier keys should be pressed with PressKey since they stay enabled until 92 // Other modifier keys should be pressed with PressKey since they stay enabled until
diff --git a/src/input_common/drivers/keyboard.h b/src/input_common/drivers/keyboard.h
index 2ab92fd6c..ad123b136 100644
--- a/src/input_common/drivers/keyboard.h
+++ b/src/input_common/drivers/keyboard.h
@@ -29,10 +29,22 @@ public:
29 void ReleaseKey(int key_code); 29 void ReleaseKey(int key_code);
30 30
31 /** 31 /**
32 * Sets the status of the keyboard key to pressed
33 * @param key_index index of the key to press
34 */
35 void PressKeyboardKey(int key_index);
36
37 /**
38 * Sets the status of the keyboard key to released
39 * @param key_index index of the key to release
40 */
41 void ReleaseKeyboardKey(int key_index);
42
43 /**
32 * Sets the status of all keyboard modifier keys 44 * Sets the status of all keyboard modifier keys
33 * @param key_modifiers the code of the key to release 45 * @param key_modifiers the code of the key to release
34 */ 46 */
35 void SetModifiers(int key_modifiers); 47 void SetKeyboardModifiers(int key_modifiers);
36 48
37 /// Sets all keys to the non pressed state 49 /// Sets all keys to the non pressed state
38 void ReleaseAllKeys(); 50 void ReleaseAllKeys();