diff options
| author | 2021-12-18 13:57:14 +0800 | |
|---|---|---|
| committer | 2021-12-18 13:57:14 +0800 | |
| commit | e49184e6069a9d791d2df3c1958f5c4b1187e124 (patch) | |
| tree | b776caf722e0be0e680f67b0ad0842628162ef1c /src/input_common/drivers/keyboard.cpp | |
| parent | Implement convert legacy to generic (diff) | |
| parent | Merge pull request #7570 from ameerj/favorites-expanded (diff) | |
| download | yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.gz yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.xz yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.zip | |
Merge branch 'yuzu-emu:master' into convert_legacy
Diffstat (limited to 'src/input_common/drivers/keyboard.cpp')
| -rw-r--r-- | src/input_common/drivers/keyboard.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp new file mode 100644 index 000000000..4c1e5bbec --- /dev/null +++ b/src/input_common/drivers/keyboard.cpp | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included | ||
| 4 | |||
| 5 | #include "common/param_package.h" | ||
| 6 | #include "common/settings_input.h" | ||
| 7 | #include "input_common/drivers/keyboard.h" | ||
| 8 | |||
| 9 | namespace InputCommon { | ||
| 10 | |||
| 11 | constexpr PadIdentifier key_identifier = { | ||
| 12 | .guid = Common::UUID{Common::INVALID_UUID}, | ||
| 13 | .port = 0, | ||
| 14 | .pad = 0, | ||
| 15 | }; | ||
| 16 | constexpr PadIdentifier keyboard_key_identifier = { | ||
| 17 | .guid = Common::UUID{Common::INVALID_UUID}, | ||
| 18 | .port = 1, | ||
| 19 | .pad = 0, | ||
| 20 | }; | ||
| 21 | constexpr PadIdentifier keyboard_modifier_identifier = { | ||
| 22 | .guid = Common::UUID{Common::INVALID_UUID}, | ||
| 23 | .port = 1, | ||
| 24 | .pad = 1, | ||
| 25 | }; | ||
| 26 | |||
| 27 | Keyboard::Keyboard(std::string input_engine_) : InputEngine(std::move(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. | ||
| 33 | PreSetController(key_identifier); | ||
| 34 | PreSetController(keyboard_key_identifier); | ||
| 35 | PreSetController(keyboard_modifier_identifier); | ||
| 36 | } | ||
| 37 | |||
| 38 | void Keyboard::PressKey(int key_code) { | ||
| 39 | SetButton(key_identifier, key_code, true); | ||
| 40 | } | ||
| 41 | |||
| 42 | void Keyboard::ReleaseKey(int key_code) { | ||
| 43 | SetButton(key_identifier, key_code, false); | ||
| 44 | } | ||
| 45 | |||
| 46 | void 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 | |||
| 53 | void 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 | |||
| 60 | void Keyboard::SetKeyboardModifiers(int key_modifiers) { | ||
| 61 | for (int i = 0; i < 32; ++i) { | ||
| 62 | bool key_value = ((key_modifiers >> i) & 0x1) != 0; | ||
| 63 | SetButton(keyboard_modifier_identifier, i, key_value); | ||
| 64 | // Use the modifier to press the key button equivalent | ||
| 65 | switch (i) { | ||
| 66 | case Settings::NativeKeyboard::LeftControl: | ||
| 67 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftControlKey, key_value); | ||
| 68 | break; | ||
| 69 | case Settings::NativeKeyboard::LeftShift: | ||
| 70 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftShiftKey, key_value); | ||
| 71 | break; | ||
| 72 | case Settings::NativeKeyboard::LeftAlt: | ||
| 73 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftAltKey, key_value); | ||
| 74 | break; | ||
| 75 | case Settings::NativeKeyboard::LeftMeta: | ||
| 76 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::LeftMetaKey, key_value); | ||
| 77 | break; | ||
| 78 | case Settings::NativeKeyboard::RightControl: | ||
| 79 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightControlKey, | ||
| 80 | key_value); | ||
| 81 | break; | ||
| 82 | case Settings::NativeKeyboard::RightShift: | ||
| 83 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightShiftKey, key_value); | ||
| 84 | break; | ||
| 85 | case Settings::NativeKeyboard::RightAlt: | ||
| 86 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightAltKey, key_value); | ||
| 87 | break; | ||
| 88 | case Settings::NativeKeyboard::RightMeta: | ||
| 89 | SetButton(keyboard_key_identifier, Settings::NativeKeyboard::RightMetaKey, key_value); | ||
| 90 | break; | ||
| 91 | default: | ||
| 92 | // Other modifier keys should be pressed with PressKey since they stay enabled until | ||
| 93 | // next press | ||
| 94 | break; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | void Keyboard::ReleaseAllKeys() { | ||
| 100 | ResetButtonState(); | ||
| 101 | } | ||
| 102 | |||
| 103 | std::vector<Common::ParamPackage> Keyboard::GetInputDevices() const { | ||
| 104 | std::vector<Common::ParamPackage> devices; | ||
| 105 | devices.emplace_back(Common::ParamPackage{ | ||
| 106 | {"engine", GetEngineName()}, | ||
| 107 | {"display", "Keyboard Only"}, | ||
| 108 | }); | ||
| 109 | return devices; | ||
| 110 | } | ||
| 111 | |||
| 112 | } // namespace InputCommon | ||