diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index aca142b9cd..d0c6a35cd0 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -93,6 +93,8 @@ add_library(common JitRegister.h JsonUtil.h JsonUtil.cpp + Keyboard.h + Keyboard.cpp Lazy.h LinearDiskCache.h Logging/ConsoleListener.h diff --git a/Source/Core/Common/Keyboard.cpp b/Source/Core/Common/Keyboard.cpp new file mode 100644 index 0000000000..346048703f --- /dev/null +++ b/Source/Core/Common/Keyboard.cpp @@ -0,0 +1,242 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "Common/Keyboard.h" + +#include +#include + +#ifdef _WIN32 +#include +#endif + +namespace +{ +// Crazy ugly +#ifdef _WIN32 +constexpr std::size_t KEYBOARD_STATE_SIZE = 256; +constexpr std::array VK_HID_QWERTY{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2A, // Backspace + 0x2B, // Tab + 0x00, 0x00, + 0x00, // Clear + 0x28, // Return + 0x00, 0x00, + 0x00, // Shift + 0x00, // Control + 0x00, // ALT + 0x48, // Pause + 0x39, // Capital + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x29, // Escape + 0x00, 0x00, 0x00, 0x00, + 0x2C, // Space + 0x4B, // Prior + 0x4E, // Next + 0x4D, // End + 0x4A, // Home + 0x50, // Left + 0x52, // Up + 0x4F, // Right + 0x51, // Down + 0x00, 0x00, 0x00, + 0x46, // Print screen + 0x49, // Insert + 0x4C, // Delete + 0x00, + // 0 -> 9 + 0x27, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, + // A -> Z + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, + // Numpad 0 -> 9 + 0x62, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, + 0x55, // Multiply + 0x57, // Add + 0x00, // Separator + 0x56, // Subtract + 0x63, // Decimal + 0x54, // Divide + // F1 -> F12 + 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + // F13 -> F24 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x53, // Numlock + 0x47, // Scroll lock + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Modifier keys + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x33, // ';' + 0x2E, // Plus + 0x36, // Comma + 0x2D, // Minus + 0x37, // Period + 0x38, // '/' + 0x35, // '~' + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2F, // '[' + 0x32, // '\' + 0x30, // ']' + 0x34, // ''' + 0x00, // + 0x00, // Nothing interesting past this point. +}; + +constexpr std::array VK_HID_AZERTY{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2A, // Backspace + 0x2B, // Tab + 0x00, 0x00, + 0x00, // Clear + 0x28, // Return + 0x00, 0x00, + 0x00, // Shift + 0x00, // Control + 0x00, // ALT + 0x48, // Pause + 0x39, // Capital + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x29, // Escape + 0x00, 0x00, 0x00, 0x00, + 0x2C, // Space + 0x4B, // Prior + 0x4E, // Next + 0x4D, // End + 0x4A, // Home + 0x50, // Left + 0x52, // Up + 0x4F, // Right + 0x51, // Down + 0x00, 0x00, 0x00, + 0x46, // Print screen + 0x49, // Insert + 0x4C, // Delete + 0x00, + // 0 -> 9 + 0x27, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, + // A -> Z + 0x14, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x33, 0x11, 0x12, 0x13, + 0x04, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1D, 0x1B, 0x1C, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, + // Numpad 0 -> 9 + 0x62, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, + 0x55, // Multiply + 0x57, // Add + 0x00, // Separator + 0x56, // Substract + 0x63, // Decimal + 0x54, // Divide + // F1 -> F12 + 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + // F13 -> F24 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x53, // Numlock + 0x47, // Scroll lock + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Modifier keys + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, // '$' + 0x2E, // Plus + 0x10, // Comma + 0x00, // Minus + 0x36, // Period + 0x37, // '/' + 0x34, // ' ' + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2D, // ')' + 0x32, // '\' + 0x2F, // '^' + 0x00, // ' ' + 0x38, // '!' + 0x00, // Nothing interesting past this point. +}; + +u8 MapVirtualKeyToHID(u8 virtual_key, int keyboard_layout) +{ + switch (keyboard_layout) + { + case Common::KBD_LAYOUT_AZERTY: + return VK_HID_AZERTY[virtual_key]; + case Common::KBD_LAYOUT_QWERTY: + default: + return VK_HID_QWERTY[virtual_key]; + } +} +#else +u8 MapVirtualKeyToHID(u8 virtual_key, int keyboard_layout) +{ + return virtual_key; +} +#endif +} // Anonymous namespace + +namespace Common +{ +bool Common::IsVirtualKeyPressed(int virtual_key) +{ +#ifdef _WIN32 + return (GetAsyncKeyState(virtual_key) & 0x8000) != 0; +#else + // TODO: do it for non-Windows platforms + return false; +#endif +} + +u8 Common::PollHIDModifiers() +{ + u8 modifiers = 0; +#ifdef _WIN32 + using VkHidPair = std::pair; + // References: + // https://learn.microsoft.com/windows/win32/inputdev/virtual-key-codes + // https://www.usb.org/document-library/device-class-definition-hid-111 + static const std::vector MODIFIERS_MAP{ + {VK_LCONTROL, 0x01}, // HID modifier: Bit 0 - LEFT CTRL + {VK_LSHIFT, 0x02}, // HID modifier: Bit 1 - LEFT SHIFT + {VK_LMENU, 0x04}, // HID modifier: Bit 2 - LEFT ALT + {VK_LWIN, 0x08}, // HID modifier: Bit 3 - LEFT GUI + {VK_RCONTROL, 0x10}, // HID modifier: Bit 4 - RIGHT CTRL + {VK_RSHIFT, 0x20}, // HID modifier: Bit 5 - RIGHT SHIFT + {VK_RMENU, 0x40}, // HID modifier: Bit 6 - RIGHT ALT + {VK_RWIN, 0x80} // HID modifier: Bit 7 - RIGHT GUI + }; + for (const auto& [virtual_key, hid_modifier] : MODIFIERS_MAP) + { + if (IsVirtualKeyPressed(virtual_key)) + modifiers |= hid_modifier; + } +#else + // TODO: Implementation for non-Windows platforms +#endif + return modifiers; +} + +HIDPressedKeys PollHIDPressedKeys(int keyboard_layout) +{ + HIDPressedKeys pressed_keys{}; + auto it = pressed_keys.begin(); + +#ifdef _WIN32 + for (std::size_t virtual_key = 0; virtual_key < KEYBOARD_STATE_SIZE; ++virtual_key) + { + if (!IsVirtualKeyPressed(static_cast(virtual_key))) + continue; + + *it = MapVirtualKeyToHID(static_cast(virtual_key), keyboard_layout); + if (++it == pressed_keys.end()) + break; + } +#else + // TODO: Implementation for non-Windows platforms +#endif + return pressed_keys; +} +} // namespace Common diff --git a/Source/Core/Common/Keyboard.h b/Source/Core/Common/Keyboard.h new file mode 100644 index 0000000000..220b450c70 --- /dev/null +++ b/Source/Core/Common/Keyboard.h @@ -0,0 +1,23 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +#include "Common/CommonTypes.h" + +namespace Common +{ +enum +{ + KBD_LAYOUT_QWERTY = 0, + KBD_LAYOUT_AZERTY = 1 +}; + +using HIDPressedKeys = std::array; + +bool IsVirtualKeyPressed(int virtual_key); +u8 PollHIDModifiers(); +HIDPressedKeys PollHIDPressedKeys(int keyboard_layout); +} // namespace Common diff --git a/Source/Core/Core/IOS/USB/USB_KBD.cpp b/Source/Core/Core/IOS/USB/USB_KBD.cpp index c0bf361e2f..9782e772f9 100644 --- a/Source/Core/Core/IOS/USB/USB_KBD.cpp +++ b/Source/Core/Core/IOS/USB/USB_KBD.cpp @@ -3,9 +3,6 @@ #include "Core/IOS/USB/USB_KBD.h" -#include -#include - #include "Common/FileUtil.h" #include "Common/IniFile.h" #include "Common/Logging/Log.h" @@ -16,169 +13,11 @@ #include "Core/System.h" #include "InputCommon/ControlReference/ControlReference.h" // For background input check -#ifdef _WIN32 -#include -#endif - namespace IOS::HLE { -namespace -{ -// Crazy ugly -#ifdef _WIN32 -constexpr std::array s_key_codes_qwerty{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2A, // Backspace - 0x2B, // Tab - 0x00, 0x00, - 0x00, // Clear - 0x28, // Return - 0x00, 0x00, - 0x00, // Shift - 0x00, // Control - 0x00, // ALT - 0x48, // Pause - 0x39, // Capital - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x29, // Escape - 0x00, 0x00, 0x00, 0x00, - 0x2C, // Space - 0x4B, // Prior - 0x4E, // Next - 0x4D, // End - 0x4A, // Home - 0x50, // Left - 0x52, // Up - 0x4F, // Right - 0x51, // Down - 0x00, 0x00, 0x00, - 0x46, // Print screen - 0x49, // Insert - 0x4C, // Delete - 0x00, - // 0 -> 9 - 0x27, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, - // A -> Z - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, - 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, - // Numpad 0 -> 9 - 0x62, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, - 0x55, // Multiply - 0x57, // Add - 0x00, // Separator - 0x56, // Subtract - 0x63, // Decimal - 0x54, // Divide - // F1 -> F12 - 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, - // F13 -> F24 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x53, // Numlock - 0x47, // Scroll lock - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // Modifier keys - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x33, // ';' - 0x2E, // Plus - 0x36, // Comma - 0x2D, // Minus - 0x37, // Period - 0x38, // '/' - 0x35, // '~' - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2F, // '[' - 0x32, // '\' - 0x30, // ']' - 0x34, // ''' - 0x00, // - 0x00, // Nothing interesting past this point. -}; - -constexpr std::array s_key_codes_azerty{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2A, // Backspace - 0x2B, // Tab - 0x00, 0x00, - 0x00, // Clear - 0x28, // Return - 0x00, 0x00, - 0x00, // Shift - 0x00, // Control - 0x00, // ALT - 0x48, // Pause - 0x39, // Capital - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x29, // Escape - 0x00, 0x00, 0x00, 0x00, - 0x2C, // Space - 0x4B, // Prior - 0x4E, // Next - 0x4D, // End - 0x4A, // Home - 0x50, // Left - 0x52, // Up - 0x4F, // Right - 0x51, // Down - 0x00, 0x00, 0x00, - 0x46, // Print screen - 0x49, // Insert - 0x4C, // Delete - 0x00, - // 0 -> 9 - 0x27, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, - // A -> Z - 0x14, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x33, 0x11, 0x12, 0x13, - 0x04, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1D, 0x1B, 0x1C, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, - // Numpad 0 -> 9 - 0x62, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, - 0x55, // Multiply - 0x57, // Add - 0x00, // Separator - 0x56, // Substract - 0x63, // Decimal - 0x54, // Divide - // F1 -> F12 - 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, - // F13 -> F24 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x53, // Numlock - 0x47, // Scroll lock - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // Modifier keys - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x30, // '$' - 0x2E, // Plus - 0x10, // Comma - 0x00, // Minus - 0x36, // Period - 0x37, // '/' - 0x34, // ' ' - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2D, // ')' - 0x32, // '\' - 0x2F, // '^' - 0x00, // ' ' - 0x38, // '!' - 0x00, // Nothing interesting past this point. -}; -#else -constexpr std::array s_key_codes_qwerty{}; - -constexpr std::array s_key_codes_azerty{}; -#endif -} // Anonymous namespace - -USB_KBD::MessageData::MessageData(MessageType type, u8 modifiers_, PressedKeyData pressed_keys_) - : msg_type{Common::swap32(static_cast(type))}, modifiers{modifiers_}, - pressed_keys{pressed_keys_} +USB_KBD::MessageData::MessageData(MessageType type, const State& state) + : msg_type{Common::swap32(static_cast(type))}, modifiers{state.modifiers}, + pressed_keys{state.pressed_keys} { } @@ -194,13 +33,13 @@ std::optional USB_KBD::Open(const OpenRequest& request) INFO_LOG_FMT(IOS, "USB_KBD: Open"); Common::IniFile ini; ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); - ini.GetOrCreateSection("USB Keyboard")->Get("Layout", &m_keyboard_layout, KBD_LAYOUT_QWERTY); + ini.GetOrCreateSection("USB Keyboard") + ->Get("Layout", &m_keyboard_layout, Common::KBD_LAYOUT_QWERTY); m_message_queue = {}; - m_old_key_buffer.fill(false); - m_old_modifiers = 0x00; + m_previous_state = {}; - // m_message_queue.emplace(MessageType::KeyboardConnect, 0, PressedKeyData{}); + // m_message_queue.emplace(MessageType::KeyboardConnect, {}); return Device::Open(request); } @@ -223,91 +62,18 @@ std::optional USB_KBD::IOCtl(const IOCtlRequest& request) return IPCReply(IPC_SUCCESS); } -bool USB_KBD::IsKeyPressed(int key) const -{ -#ifdef _WIN32 - return (GetAsyncKeyState(key) & 0x8000) != 0; -#else - // TODO: do it for non-Windows platforms - return false; -#endif -} - void USB_KBD::Update() { if (!Config::Get(Config::MAIN_WII_KEYBOARD) || Core::WantsDeterminism() || !m_is_active) return; - u8 modifiers = 0x00; - PressedKeyData pressed_keys{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - bool got_event = false; - size_t num_pressed_keys = 0; - for (size_t i = 0; i < m_old_key_buffer.size(); i++) - { - const bool key_pressed_now = IsKeyPressed(static_cast(i)); - const bool key_pressed_before = m_old_key_buffer[i]; - u8 key_code = 0; + const State current_state{.modifiers = Common::PollHIDModifiers(), + .pressed_keys = Common::PollHIDPressedKeys(m_keyboard_layout)}; - if (key_pressed_now ^ key_pressed_before) - { - if (key_pressed_now) - { - switch (m_keyboard_layout) - { - case KBD_LAYOUT_QWERTY: - key_code = s_key_codes_qwerty[i]; - break; + if (current_state == m_previous_state) + return; - case KBD_LAYOUT_AZERTY: - key_code = s_key_codes_azerty[i]; - break; - } - - if (key_code == 0x00) - continue; - - pressed_keys[num_pressed_keys] = key_code; - - num_pressed_keys++; - if (num_pressed_keys == pressed_keys.size()) - break; - } - - got_event = true; - } - - m_old_key_buffer[i] = key_pressed_now; - } - -#ifdef _WIN32 - if (GetAsyncKeyState(VK_LCONTROL) & 0x8000) - modifiers |= 0x01; - if (GetAsyncKeyState(VK_LSHIFT) & 0x8000) - modifiers |= 0x02; - if (GetAsyncKeyState(VK_MENU) & 0x8000) - modifiers |= 0x04; - if (GetAsyncKeyState(VK_LWIN) & 0x8000) - modifiers |= 0x08; - if (GetAsyncKeyState(VK_RCONTROL) & 0x8000) - modifiers |= 0x10; - if (GetAsyncKeyState(VK_RSHIFT) & 0x8000) - modifiers |= 0x20; - // TODO: VK_MENU is for ALT, not for ALT GR (ALT GR seems to work though...) - if (GetAsyncKeyState(VK_MENU) & 0x8000) - modifiers |= 0x40; - if (GetAsyncKeyState(VK_RWIN) & 0x8000) - modifiers |= 0x80; -#else -// TODO: modifiers for non-Windows platforms -#endif - - if (modifiers ^ m_old_modifiers) - { - got_event = true; - m_old_modifiers = modifiers; - } - - if (got_event) - m_message_queue.emplace(MessageType::Event, modifiers, pressed_keys); + m_message_queue.emplace(MessageType::Event, current_state); + m_previous_state = std::move(current_state); } } // namespace IOS::HLE diff --git a/Source/Core/Core/IOS/USB/USB_KBD.h b/Source/Core/Core/IOS/USB/USB_KBD.h index ea928b1236..76feb34485 100644 --- a/Source/Core/Core/IOS/USB/USB_KBD.h +++ b/Source/Core/Core/IOS/USB/USB_KBD.h @@ -3,12 +3,11 @@ #pragma once -#include #include #include -#include #include "Common/CommonTypes.h" +#include "Common/Keyboard.h" #include "Core/IOS/Device.h" #include "Core/IOS/IOS.h" @@ -32,7 +31,13 @@ private: Event = 2 }; - using PressedKeyData = std::array; + struct State + { + u8 modifiers = 0; + Common::HIDPressedKeys pressed_keys{}; + + auto operator<=>(const State&) const = default; + }; #pragma pack(push, 1) struct MessageData @@ -41,26 +46,15 @@ private: u32 unk1 = 0; u8 modifiers = 0; u8 unk2 = 0; - PressedKeyData pressed_keys{}; + Common::HIDPressedKeys pressed_keys{}; - MessageData(MessageType msg_type, u8 modifiers, PressedKeyData pressed_keys); + MessageData(MessageType msg_type, const State& state); }; static_assert(std::is_trivially_copyable_v, "MessageData must be trivially copyable, as it's copied into emulated memory."); #pragma pack(pop) std::queue m_message_queue; - - std::array m_old_key_buffer{}; - u8 m_old_modifiers = 0; - - bool IsKeyPressed(int key) const; - - // This stuff should probably die - enum - { - KBD_LAYOUT_QWERTY = 0, - KBD_LAYOUT_AZERTY = 1 - }; - int m_keyboard_layout = KBD_LAYOUT_QWERTY; + State m_previous_state; + int m_keyboard_layout = Common::KBD_LAYOUT_QWERTY; }; } // namespace IOS::HLE diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index d7bb245d29..33eb6a8c90 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -132,6 +132,7 @@ + @@ -830,6 +831,7 @@ +