| 1 |
/* |
| 2 |
* Copyright (C) 2017-2024 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GamepadTranslator.h" |
| 10 |
|
| 11 |
#include "input/keyboard/KeyIDs.h" |
| 12 |
#include "utils/StringUtils.h" |
| 13 |
#include "utils/log.h" |
| 14 |
|
| 15 |
#include <string> |
| 16 |
|
| 17 |
using namespace KODI; |
| 18 |
using namespace KEYMAP; |
| 19 |
|
| 20 |
uint32_t CGamepadTranslator::TranslateString(std::string strButton) |
| 21 |
{ |
| 22 |
if (strButton.empty()) |
| 23 |
return 0; |
| 24 |
|
| 25 |
StringUtils::ToLower(strButton); |
| 26 |
|
| 27 |
uint32_t buttonCode = 0; |
| 28 |
if (strButton == "a") |
| 29 |
buttonCode = KEY_BUTTON_A; |
| 30 |
else if (strButton == "b") |
| 31 |
buttonCode = KEY_BUTTON_B; |
| 32 |
else if (strButton == "x") |
| 33 |
buttonCode = KEY_BUTTON_X; |
| 34 |
else if (strButton == "y") |
| 35 |
buttonCode = KEY_BUTTON_Y; |
| 36 |
else if (strButton == "white") |
| 37 |
buttonCode = KEY_BUTTON_WHITE; |
| 38 |
else if (strButton == "black") |
| 39 |
buttonCode = KEY_BUTTON_BLACK; |
| 40 |
else if (strButton == "start") |
| 41 |
buttonCode = KEY_BUTTON_START; |
| 42 |
else if (strButton == "back") |
| 43 |
buttonCode = KEY_BUTTON_BACK; |
| 44 |
else if (strButton == "leftthumbbutton") |
| 45 |
buttonCode = KEY_BUTTON_LEFT_THUMB_BUTTON; |
| 46 |
else if (strButton == "rightthumbbutton") |
| 47 |
buttonCode = KEY_BUTTON_RIGHT_THUMB_BUTTON; |
| 48 |
else if (strButton == "leftthumbstick") |
| 49 |
buttonCode = KEY_BUTTON_LEFT_THUMB_STICK; |
| 50 |
else if (strButton == "leftthumbstickup") |
| 51 |
buttonCode = KEY_BUTTON_LEFT_THUMB_STICK_UP; |
| 52 |
else if (strButton == "leftthumbstickdown") |
| 53 |
buttonCode = KEY_BUTTON_LEFT_THUMB_STICK_DOWN; |
| 54 |
else if (strButton == "leftthumbstickleft") |
| 55 |
buttonCode = KEY_BUTTON_LEFT_THUMB_STICK_LEFT; |
| 56 |
else if (strButton == "leftthumbstickright") |
| 57 |
buttonCode = KEY_BUTTON_LEFT_THUMB_STICK_RIGHT; |
| 58 |
else if (strButton == "rightthumbstick") |
| 59 |
buttonCode = KEY_BUTTON_RIGHT_THUMB_STICK; |
| 60 |
else if (strButton == "rightthumbstickup") |
| 61 |
buttonCode = KEY_BUTTON_RIGHT_THUMB_STICK_UP; |
| 62 |
else if (strButton == "rightthumbstickdown") |
| 63 |
buttonCode = KEY_BUTTON_RIGHT_THUMB_STICK_DOWN; |
| 64 |
else if (strButton == "rightthumbstickleft") |
| 65 |
buttonCode = KEY_BUTTON_RIGHT_THUMB_STICK_LEFT; |
| 66 |
else if (strButton == "rightthumbstickright") |
| 67 |
buttonCode = KEY_BUTTON_RIGHT_THUMB_STICK_RIGHT; |
| 68 |
else if (strButton == "lefttrigger") |
| 69 |
buttonCode = KEY_BUTTON_LEFT_TRIGGER; |
| 70 |
else if (strButton == "righttrigger") |
| 71 |
buttonCode = KEY_BUTTON_RIGHT_TRIGGER; |
| 72 |
else if (strButton == "leftanalogtrigger") |
| 73 |
buttonCode = KEY_BUTTON_LEFT_ANALOG_TRIGGER; |
| 74 |
else if (strButton == "rightanalogtrigger") |
| 75 |
buttonCode = KEY_BUTTON_RIGHT_ANALOG_TRIGGER; |
| 76 |
else if (strButton == "dpadleft") |
| 77 |
buttonCode = KEY_BUTTON_DPAD_LEFT; |
| 78 |
else if (strButton == "dpadright") |
| 79 |
buttonCode = KEY_BUTTON_DPAD_RIGHT; |
| 80 |
else if (strButton == "dpadup") |
| 81 |
buttonCode = KEY_BUTTON_DPAD_UP; |
| 82 |
else if (strButton == "dpaddown") |
| 83 |
buttonCode = KEY_BUTTON_DPAD_DOWN; |
| 84 |
else |
| 85 |
CLog::Log(LOGERROR, "Gamepad Translator: Can't find button {}", strButton); |
| 86 |
|
| 87 |
return buttonCode; |
| 88 |
} |