diff options
Diffstat (limited to 'src/input_common/drivers')
| -rw-r--r-- | src/input_common/drivers/keyboard.cpp | 35 | ||||
| -rw-r--r-- | src/input_common/drivers/keyboard.h | 44 |
2 files changed, 79 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..b00a4b8d9 --- /dev/null +++ b/src/input_common/drivers/keyboard.cpp | |||
| @@ -0,0 +1,35 @@ | |||
| 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 "input_common/drivers/keyboard.h" | ||
| 7 | |||
| 8 | namespace InputCommon { | ||
| 9 | |||
| 10 | Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { | ||
| 11 | PreSetController(identifier); | ||
| 12 | } | ||
| 13 | |||
| 14 | void Keyboard::PressKey(int key_code) { | ||
| 15 | SetButton(identifier, key_code, true); | ||
| 16 | } | ||
| 17 | |||
| 18 | void Keyboard::ReleaseKey(int key_code) { | ||
| 19 | SetButton(identifier, key_code, false); | ||
| 20 | } | ||
| 21 | |||
| 22 | void Keyboard::ReleaseAllKeys() { | ||
| 23 | ResetButtonState(); | ||
| 24 | } | ||
| 25 | |||
| 26 | std::vector<Common::ParamPackage> Keyboard::GetInputDevices() const { | ||
| 27 | std::vector<Common::ParamPackage> devices; | ||
| 28 | devices.emplace_back(Common::ParamPackage{ | ||
| 29 | {"engine", "keyboard"}, | ||
| 30 | {"display", "Keyboard Only"}, | ||
| 31 | }); | ||
| 32 | return devices; | ||
| 33 | } | ||
| 34 | |||
| 35 | } // namespace InputCommon | ||
diff --git a/src/input_common/drivers/keyboard.h b/src/input_common/drivers/keyboard.h new file mode 100644 index 000000000..a3e0d8a61 --- /dev/null +++ b/src/input_common/drivers/keyboard.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "input_common/input_engine.h" | ||
| 8 | |||
| 9 | namespace InputCommon { | ||
| 10 | |||
| 11 | /** | ||
| 12 | * A button device factory representing a keyboard. It receives keyboard events and forward them | ||
| 13 | * to all button devices it created. | ||
| 14 | */ | ||
| 15 | class Keyboard final : public InputCommon::InputEngine { | ||
| 16 | public: | ||
| 17 | explicit Keyboard(const std::string& input_engine_); | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Sets the status of all buttons bound with the key to pressed | ||
| 21 | * @param key_code the code of the key to press | ||
| 22 | */ | ||
| 23 | void PressKey(int key_code); | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Sets the status of all buttons bound with the key to released | ||
| 27 | * @param key_code the code of the key to release | ||
| 28 | */ | ||
| 29 | void ReleaseKey(int key_code); | ||
| 30 | |||
| 31 | void ReleaseAllKeys(); | ||
| 32 | |||
| 33 | /// Used for automapping features | ||
| 34 | std::vector<Common::ParamPackage> GetInputDevices() const override; | ||
| 35 | |||
| 36 | private: | ||
| 37 | const PadIdentifier identifier = { | ||
| 38 | .guid = Common::UUID{""}, | ||
| 39 | .port = 0, | ||
| 40 | .pad = 0, | ||
| 41 | }; | ||
| 42 | }; | ||
| 43 | |||
| 44 | } // namespace InputCommon | ||