diff options
Diffstat (limited to 'src/input_common/drivers/keyboard.cpp')
| -rw-r--r-- | src/input_common/drivers/keyboard.cpp | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp index 549704e89..328fe1ac1 100644 --- a/src/input_common/drivers/keyboard.cpp +++ b/src/input_common/drivers/keyboard.cpp | |||
| @@ -3,26 +3,71 @@ | |||
| 3 | // Refer to the license.txt file included | 3 | // Refer to the license.txt file included |
| 4 | 4 | ||
| 5 | #include "common/param_package.h" | 5 | #include "common/param_package.h" |
| 6 | #include "common/settings_input.h" | ||
| 6 | #include "input_common/drivers/keyboard.h" | 7 | #include "input_common/drivers/keyboard.h" |
| 7 | 8 | ||
| 8 | namespace InputCommon { | 9 | namespace InputCommon { |
| 9 | 10 | ||
| 10 | constexpr PadIdentifier identifier = { | 11 | constexpr PadIdentifier key_identifier = { |
| 11 | .guid = Common::UUID{Common::INVALID_UUID}, | 12 | .guid = Common::UUID{Common::INVALID_UUID}, |
| 12 | .port = 0, | 13 | .port = 0, |
| 13 | .pad = 0, | 14 | .pad = 0, |
| 14 | }; | 15 | }; |
| 16 | constexpr PadIdentifier modifier_identifier = { | ||
| 17 | .guid = Common::UUID{Common::INVALID_UUID}, | ||
| 18 | .port = 0, | ||
| 19 | .pad = 1, | ||
| 20 | }; | ||
| 15 | 21 | ||
| 16 | Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { | 22 | Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { |
| 17 | PreSetController(identifier); | 23 | PreSetController(key_identifier); |
| 24 | PreSetController(modifier_identifier); | ||
| 18 | } | 25 | } |
| 19 | 26 | ||
| 20 | void Keyboard::PressKey(int key_code) { | 27 | void Keyboard::PressKey(int key_code) { |
| 21 | SetButton(identifier, key_code, true); | 28 | SetButton(key_identifier, key_code, true); |
| 22 | } | 29 | } |
| 23 | 30 | ||
| 24 | void Keyboard::ReleaseKey(int key_code) { | 31 | void Keyboard::ReleaseKey(int key_code) { |
| 25 | SetButton(identifier, key_code, false); | 32 | SetButton(key_identifier, key_code, false); |
| 33 | } | ||
| 34 | |||
| 35 | void Keyboard::SetModifiers(int key_modifiers) { | ||
| 36 | for (int i = 0; i < 32; ++i) { | ||
| 37 | bool key_value = ((key_modifiers >> i) & 0x1) != 0; | ||
| 38 | SetButton(modifier_identifier, i, key_value); | ||
| 39 | // Use the modifier to press the key button equivalent | ||
| 40 | switch (i) { | ||
| 41 | case Settings::NativeKeyboard::LeftControl: | ||
| 42 | SetButton(key_identifier, Settings::NativeKeyboard::LeftControlKey, key_value); | ||
| 43 | break; | ||
| 44 | case Settings::NativeKeyboard::LeftShift: | ||
| 45 | SetButton(key_identifier, Settings::NativeKeyboard::LeftShiftKey, key_value); | ||
| 46 | break; | ||
| 47 | case Settings::NativeKeyboard::LeftAlt: | ||
| 48 | SetButton(key_identifier, Settings::NativeKeyboard::LeftAltKey, key_value); | ||
| 49 | break; | ||
| 50 | case Settings::NativeKeyboard::LeftMeta: | ||
| 51 | SetButton(key_identifier, Settings::NativeKeyboard::LeftMetaKey, key_value); | ||
| 52 | break; | ||
| 53 | case Settings::NativeKeyboard::RightControl: | ||
| 54 | SetButton(key_identifier, Settings::NativeKeyboard::RightControlKey, key_value); | ||
| 55 | break; | ||
| 56 | case Settings::NativeKeyboard::RightShift: | ||
| 57 | SetButton(key_identifier, Settings::NativeKeyboard::RightShiftKey, key_value); | ||
| 58 | break; | ||
| 59 | case Settings::NativeKeyboard::RightAlt: | ||
| 60 | SetButton(key_identifier, Settings::NativeKeyboard::RightAltKey, key_value); | ||
| 61 | break; | ||
| 62 | case Settings::NativeKeyboard::RightMeta: | ||
| 63 | SetButton(key_identifier, Settings::NativeKeyboard::RightMetaKey, key_value); | ||
| 64 | break; | ||
| 65 | default: | ||
| 66 | // Other modifier keys should be pressed with PressKey since they stay enabled until | ||
| 67 | // next press | ||
| 68 | break; | ||
| 69 | } | ||
| 70 | } | ||
| 26 | } | 71 | } |
| 27 | 72 | ||
| 28 | void Keyboard::ReleaseAllKeys() { | 73 | void Keyboard::ReleaseAllKeys() { |