diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/drivers/keyboard.cpp | 53 | ||||
| -rw-r--r-- | src/input_common/drivers/keyboard.h | 7 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 9 | ||||
| -rw-r--r-- | src/input_common/main.h | 3 |
4 files changed, 68 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() { |
diff --git a/src/input_common/drivers/keyboard.h b/src/input_common/drivers/keyboard.h index 46fe78576..2ab92fd6c 100644 --- a/src/input_common/drivers/keyboard.h +++ b/src/input_common/drivers/keyboard.h | |||
| @@ -28,6 +28,13 @@ public: | |||
| 28 | */ | 28 | */ |
| 29 | void ReleaseKey(int key_code); | 29 | void ReleaseKey(int key_code); |
| 30 | 30 | ||
| 31 | /** | ||
| 32 | * Sets the status of all keyboard modifier keys | ||
| 33 | * @param key_modifiers the code of the key to release | ||
| 34 | */ | ||
| 35 | void SetModifiers(int key_modifiers); | ||
| 36 | |||
| 37 | /// Sets all keys to the non pressed state | ||
| 31 | void ReleaseAllKeys(); | 38 | void ReleaseAllKeys(); |
| 32 | 39 | ||
| 33 | /// Used for automapping features | 40 | /// Used for automapping features |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index df36a337c..ae2518f53 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -402,6 +402,15 @@ std::string GenerateKeyboardParam(int key_code) { | |||
| 402 | return param.Serialize(); | 402 | return param.Serialize(); |
| 403 | } | 403 | } |
| 404 | 404 | ||
| 405 | std::string GenerateModdifierKeyboardParam(int key_code) { | ||
| 406 | Common::ParamPackage param; | ||
| 407 | param.Set("engine", "keyboard"); | ||
| 408 | param.Set("code", key_code); | ||
| 409 | param.Set("toggle", false); | ||
| 410 | param.Set("pad", 1); | ||
| 411 | return param.Serialize(); | ||
| 412 | } | ||
| 413 | |||
| 405 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | 414 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, |
| 406 | int key_modifier, float modifier_scale) { | 415 | int key_modifier, float modifier_scale) { |
| 407 | Common::ParamPackage circle_pad_param{ | 416 | Common::ParamPackage circle_pad_param{ |
diff --git a/src/input_common/main.h b/src/input_common/main.h index a4a24d076..9ea395465 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -134,6 +134,9 @@ private: | |||
| 134 | /// Generates a serialized param package for creating a keyboard button device. | 134 | /// Generates a serialized param package for creating a keyboard button device. |
| 135 | std::string GenerateKeyboardParam(int key_code); | 135 | std::string GenerateKeyboardParam(int key_code); |
| 136 | 136 | ||
| 137 | /// Generates a serialized param package for creating a moddifier keyboard button device. | ||
| 138 | std::string GenerateModdifierKeyboardParam(int key_code); | ||
| 139 | |||
| 137 | /// Generates a serialized param package for creating an analog device taking input from keyboard. | 140 | /// Generates a serialized param package for creating an analog device taking input from keyboard. |
| 138 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | 141 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, |
| 139 | int key_modifier, float modifier_scale); | 142 | int key_modifier, float modifier_scale); |