Xbox Cloud Gaming app for PS5 Homebrew
C
WIP: USB keyboard and mouse (native, for the games that take them)
Rafael Abud Ferreira19a6887dd7aa
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 51f4b4d..4a0f265 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -34,6 +34,8 @@ add_library(xcloud_core STATICsrc/xcloud/titlehub.cppsrc/xcloud/regions.cppsrc/xcloud/prices.cpp+ src/input/kbm.cpp+ src/input/kbm_map.cppsrc/xcloud/social.cppsrc/platform/posix_common.cpp)diff --git a/ps5/stubs/libSceMouse.c b/ps5/stubs/libSceMouse.cnew file mode 100644index 0000000..08f8ee1--- /dev/null+++ b/ps5/stubs/libSceMouse.c@@ -0,0 +1,8 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+/* Host-link only: names the module's exports so the native-app converter+ * records the imports. Never packaged or executed. */+int sceMouseInit(void) { return -1; }+int sceMouseOpen(int user, int type, int index, const void *param) { (void)user; (void)type; (void)index; (void)param; return -1; }+int sceMouseRead(int handle, void *data, int count) { (void)handle; (void)data; (void)count; return -1; }+int sceMouseClose(int handle) { (void)handle; return -1; }diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex e8b28e3..a1f72b4 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -15,6 +15,7 @@#include "display/display.h"#include "display/gpu.h"#include "input/controller.h"+#include "input/kbm.h"#include "input/tuning.h"#include "net/http.h"#include "platform/platform.h"@@ -214,6 +215,7 @@ int main(int argc, char** argv) {}bool haveDisplay = display::init(!g_autoplay.cpuDisplay);if (!input::init()) XC_LOGE("controller init failed");+ input::kbmInit(input::padUserId(0)); // USB keyboards and mice (logs what it found)ui::Fonts fonts;if (!fonts.load(platform::assetDir() + "/fonts")) XC_LOGE("fonts missing in %s", platform::assetDir().c_str());diff --git a/src/app/stream_player.cpp b/src/app/stream_player.cppindex f1f5779..87b2951 100644--- a/src/app/stream_player.cpp+++ b/src/app/stream_player.cpp@@ -673,6 +673,24 @@ void StreamPlayer::sendInput(const input::ControllerState& p, int index) {s->sendGamepad(f);}+void StreamPlayer::sendKbm(const input::KbmInput& in) {+ auto s = impl_->current();+ if (!s || !impl_->running) return;+ if (!in.keys.empty()) {+ std::vector<stream::KeyFrame> keys;+ for (const auto& k : in.keys) keys.push_back({k.vk, k.pressed});+ s->sendKeys(keys);+ }+ if (in.moved) {+ stream::MouseFrame m;+ m.dx = in.dx * 2; // as the web client: twice the pointer's movement+ m.dy = in.dy * 2;+ m.wheelY = in.wheel;+ m.buttons = in.buttons;+ s->sendMouse(m);+ }+}+bool StreamPlayer::titleFocused() const { return impl_->titleFocused; }void StreamPlayer::setTouchEnabled(bool on) {diff --git a/src/app/stream_player.h b/src/app/stream_player.hindex 5e9cda2..259e05a 100644--- a/src/app/stream_player.h+++ b/src/app/stream_player.h@@ -6,6 +6,7 @@#pragma once#include "input/controller.h"+#include "input/kbm.h"#include "stream/stream_session.h"#include "xcloud/gssv.h"@@ -26,6 +27,8 @@ public:// From the input thread, once per polled pad state; `index` 0..3 is the// controller's slot (input::pollPad).void sendInput(const input::ControllerState& pad, int index = 0);+ // USB mouse and keyboard (input/kbm.h), for the games that take them.+ void sendKbm(const input::KbmInput& in);// False while another window has the focus on the cloud console (the// account picker, a publisher's page).bool titleFocused() const;diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex 32a98fa..9b652a7 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -8,6 +8,7 @@#include "app/stream_player.h"#include "display/display.h"#include "display/gpu.h"+#include "input/kbm.h"#include "media/audio_out.h"#include "platform/platform.h"#include "ui/strings.h"@@ -335,6 +336,8 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b}if (platform::nowMs() < g_xboxButtonUntil) sent.btnNexus = true;g_player->sendInput(sent);+ // USB keyboard and mouse: straight to the game (those that take them).+ g_player->sendKbm(input::kbmPoll());// The other players' controllers, straight to the game.for (int i = 1; i < input::kMaxPads; ++i) {input::ControllerState other;diff --git a/src/input/kbm.cpp b/src/input/kbm.cppnew file mode 100644index 0000000..08599da--- /dev/null+++ b/src/input/kbm.cpp@@ -0,0 +1,204 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#include "input/kbm.h"++#include "platform/platform.h"+#include "util/log.h"++#include <algorithm>+#include <cstddef>+#include <string>++#if defined(XCLOUD_PS5)++extern "C" {+int sceSysmoduleLoadModule(uint16_t id);+int sceKernelLoadStartModule(const char* path, size_t argc, const void* argv, uint32_t flags, void* opt, int* res);+const char* sceKernelGetFsSandboxRandomWord(void);+int sceKeyboardInit(void);+int sceKeyboardOpen(int32_t user, int32_t type, int32_t index, const void* param);+int sceKeyboardRead(int32_t handle, void* data, int32_t count);+int sceKeyboardClose(int32_t handle);+// libSceMouse: no stub in the SDK (ps5/stubs/libSceMouse.c names them).+int sceMouseInit(void);+int sceMouseOpen(int32_t user, int32_t type, int32_t index, const void* param);+int sceMouseRead(int32_t handle, void* data, int32_t count);+int sceMouseClose(int32_t handle);+}++namespace xc::input {++namespace {++// The keyboard library's state record (ProsperoLight / ProsperoStore+// verified it on a console).+struct KeyboardState {+ uint64_t timestampUs;+ uint8_t intercepted;+ uint8_t reserved0[7];+ uint8_t connected;+ uint8_t reserved1[3];+ int32_t length; // keys[] in use+ uint32_t leds;+ uint32_t modifiers; // HID modifier bits+ uint16_t keys[16]; // HID usages held+ uint8_t reserved2[32];+};+static_assert(sizeof(KeyboardState) == 96);+static_assert(offsetof(KeyboardState, connected) == 0x10);+static_assert(offsetof(KeyboardState, modifiers) == 0x1c);+static_assert(offsetof(KeyboardState, keys) == 0x20);++// The mouse library's record (as the PS4's).+struct MouseState {+ uint64_t timestamp;+ bool connected;+ uint32_t buttons;+ int32_t x, y, wheel, tilt;+ uint8_t reserved[8];+};+static_assert(sizeof(MouseState) == 40);++constexpr int kSlots = 2;+constexpr uint64_t kRescanMs = 3000;++int32_t g_user = -1;+bool g_keyboardReady = false, g_mouseReady = false;+int g_keyboards[kSlots] = {-1, -1}, g_mice[kSlots] = {-1, -1};+uint64_t g_nextScanMs = 0;+std::vector<uint8_t> g_held; // virtual keys down, sorted+uint8_t g_buttons = 0;+bool g_loggedKeyboard = false, g_loggedMouse = false;++std::string systemLib(const char* name) {+ const char* word = sceKernelGetFsSandboxRandomWord();+ return std::string("/") + (word ? word : "") + "/common/lib/" + name;+}++void rescan(uint64_t now) {+ if (now < g_nextScanMs) return;+ g_nextScanMs = now + kRescanMs;+ const uint64_t param = 0;+ for (int i = 0; i < kSlots; ++i) {+ if (g_keyboardReady && g_keyboards[i] < 0) {+ int h = sceKeyboardOpen(g_user, 0, i, ¶m);+ if (h >= 0) {+ g_keyboards[i] = h;+ XC_LOGI("keyboard %d opened", i + 1);+ }+ }+ if (g_mouseReady && g_mice[i] < 0) {+ int h = sceMouseOpen(g_user, 0, i, ¶m);+ if (h >= 0) {+ g_mice[i] = h;+ XC_LOGI("mouse %d opened", i + 1);+ }+ }+ }+}++} // namespace++bool kbmInit(int32_t userId) {+ g_user = userId;+ int rc = sceSysmoduleLoadModule(0x0106); // libSceKeyboard+ if (rc >= 0) rc = sceKeyboardInit();+ g_keyboardReady = rc >= 0;+ XC_LOGI("keyboard library: 0x%08x", static_cast<unsigned>(rc));+ int res = 0;+ int module = sceKernelLoadStartModule(systemLib("libSceMouse.sprx").c_str(), 0, nullptr, 0, nullptr, &res);+ rc = module >= 0 ? sceMouseInit() : module;+ g_mouseReady = rc >= 0;+ XC_LOGI("mouse library: 0x%08x", static_cast<unsigned>(rc));+ rescan(platform::nowMs()); // what is plugged in at the start, in the log+ return g_keyboardReady || g_mouseReady;+}++KbmInput kbmPoll() {+ KbmInput out;+ if (!g_keyboardReady && !g_mouseReady) return out;+ rescan(platform::nowMs());++ // Keyboards: the newest record says what is held now.+ std::vector<uint8_t> held;+ KeyboardState ks[16];+ for (int i = 0; i < kSlots; ++i) {+ if (g_keyboards[i] < 0) continue;+ int n = sceKeyboardRead(g_keyboards[i], ks, 16);+ if (n < 0) { // gone: closed, reopened at the next scan+ sceKeyboardClose(g_keyboards[i]);+ g_keyboards[i] = -1;+ continue;+ }+ if (n == 0) continue;+ const KeyboardState& k = ks[std::min(n, 16) - 1];+ if (!k.connected) continue;+ out.keyboard = true;+ if (!g_loggedKeyboard) {+ g_loggedKeyboard = true;+ XC_LOGI("keyboard in use");+ }+ if (k.intercepted) continue; // the system has it (its own keyboard UI)+ for (int b = 0; b < 8; ++b)+ if (k.modifiers & (1u << b)) held.push_back(modifierVk(b));+ for (int j = 0; j < std::clamp(k.length, 0, 16); ++j)+ if (uint8_t vk = hidToVk(k.keys[j])) held.push_back(vk);+ }+ std::sort(held.begin(), held.end());+ held.erase(std::unique(held.begin(), held.end()), held.end());+ for (uint8_t vk : g_held)+ if (!std::binary_search(held.begin(), held.end(), vk)) out.keys.push_back({vk, false});+ for (uint8_t vk : held)+ if (!std::binary_search(g_held.begin(), g_held.end(), vk)) out.keys.push_back({vk, true});+ g_held.swap(held);+ static int logged = 0; // the first few, to check a keyboard works (not what is typed after)+ for (const auto& e : out.keys)+ if (logged < 10) XC_LOGI("keyboard: key 0x%02x %s (%d)", e.vk, e.pressed ? "down" : "up", ++logged);++ // Mice: the movement and wheel add up; the buttons are the newest.+ MouseState ms[32];+ uint8_t buttons = g_buttons;+ bool anyMouse = false;+ for (int i = 0; i < kSlots; ++i) {+ if (g_mice[i] < 0) continue;+ int n = sceMouseRead(g_mice[i], ms, 32);+ if (n < 0) {+ sceMouseClose(g_mice[i]);+ g_mice[i] = -1;+ continue;+ }+ for (int j = 0; j < std::min(n, 32); ++j) {+ if (!ms[j].connected) continue;+ anyMouse = true;+ out.dx += ms[j].x;+ out.dy += ms[j].y;+ out.wheel += ms[j].wheel;+ buttons = static_cast<uint8_t>(ms[j].buttons & 0x1F);+ }+ }+ if (anyMouse) {+ out.mouse = true;+ if (!g_loggedMouse) {+ g_loggedMouse = true;+ XC_LOGI("mouse in use");+ }+ }+ out.buttons = buttons;+ out.moved = out.dx || out.dy || out.wheel || buttons != g_buttons;+ static int movesLogged = 0;+ if (out.moved && movesLogged < 10)+ XC_LOGI("mouse: %d,%d wheel %d buttons 0x%02x (%d)", out.dx, out.dy, out.wheel, buttons, ++movesLogged);+ g_buttons = buttons;+ return out;+}++} // namespace xc::input++#else // the desktop build: no USB devices read++namespace xc::input {+bool kbmInit(int32_t) { return false; }+KbmInput kbmPoll() { return {}; }+} // namespace xc::input++#endifdiff --git a/src/input/kbm.h b/src/input/kbm.hnew file mode 100644index 0000000..b4c982f--- /dev/null+++ b/src/input/kbm.h@@ -0,0 +1,41 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// USB keyboards and mice on the PS5, for the games that take native mouse+// and keyboard in the cloud (Fortnite and others). The console's keyboard+// library (libSceKeyboard) and mouse library (libSceMouse, loaded at run+// time) are read each frame; keys come out as Windows virtual-key codes,+// which is what the xbox.com client sends.+#pragma once++#include <cstdint>+#include <vector>++namespace xc::input {++// A key that went down or up since the last poll.+struct KeyEvent {+ uint8_t vk = 0; // Windows virtual-key code+ bool pressed = false;+};++struct KbmInput {+ bool keyboard = false, mouse = false; // connected+ std::vector<KeyEvent> keys;+ int32_t dx = 0, dy = 0, wheel = 0; // mouse movement and wheel steps since the last poll+ uint8_t buttons = 0; // 1 left, 2 right, 4 middle, 8 back, 16 forward+ bool moved = false; // anything to send for the mouse (movement, wheel or buttons changed)+};++// USB HID usage (keyboard page) -> Windows virtual-key code; 0 for none.+uint8_t hidToVk(uint16_t usage);+// The HID modifier bits (left ctrl 0x01 ... right GUI 0x80) -> virtual keys:+// the eight modifier keys as the web client reports them (shift 0x10,+// ctrl 0x11, alt 0x12 for both sides; the Windows keys 0x5B / 0x5C).+uint8_t modifierVk(int bit);++// Loads the libraries; false when neither can be used (it isn't fatal).+bool kbmInit(int32_t userId);+// What happened since the last call. Rescans for devices every few seconds.+KbmInput kbmPoll();++} // namespace xc::inputdiff --git a/src/input/kbm_map.cpp b/src/input/kbm_map.cppnew file mode 100644index 0000000..e2d2201--- /dev/null+++ b/src/input/kbm_map.cpp@@ -0,0 +1,64 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#include "input/kbm.h"++namespace xc::input {++uint8_t hidToVk(uint16_t u) {+ if (u >= 0x04 && u <= 0x1D) return static_cast<uint8_t>('A' + (u - 0x04)); // a..z+ if (u >= 0x1E && u <= 0x26) return static_cast<uint8_t>('1' + (u - 0x1E)); // 1..9+ if (u >= 0x3A && u <= 0x45) return static_cast<uint8_t>(0x70 + (u - 0x3A)); // F1..F12+ if (u >= 0x59 && u <= 0x61) return static_cast<uint8_t>(0x61 + (u - 0x59)); // keypad 1..9+ switch (u) {+ case 0x27: return '0';+ case 0x28: return 0x0D; // enter+ case 0x29: return 0x1B; // escape+ case 0x2A: return 0x08; // backspace+ case 0x2B: return 0x09; // tab+ case 0x2C: return 0x20; // space+ case 0x2D: return 0xBD; // - _+ case 0x2E: return 0xBB; // = ++ case 0x2F: return 0xDB; // [ {+ case 0x30: return 0xDD; // ] }+ case 0x31: return 0xDC; // \ |+ case 0x32: return 0xDC; // non-US # ~+ case 0x33: return 0xBA; // ; :+ case 0x34: return 0xDE; // ' "+ case 0x35: return 0xC0; // ` ~+ case 0x36: return 0xBC; // , <+ case 0x37: return 0xBE; // . >+ case 0x38: return 0xBF; // / ?+ case 0x39: return 0x14; // caps lock+ case 0x46: return 0x2C; // print screen+ case 0x47: return 0x91; // scroll lock+ case 0x48: return 0x13; // pause+ case 0x49: return 0x2D; // insert+ case 0x4A: return 0x24; // home+ case 0x4B: return 0x21; // page up+ case 0x4C: return 0x2E; // delete+ case 0x4D: return 0x23; // end+ case 0x4E: return 0x22; // page down+ case 0x4F: return 0x27; // right+ case 0x50: return 0x25; // left+ case 0x51: return 0x28; // down+ case 0x52: return 0x26; // up+ case 0x53: return 0x90; // num lock+ case 0x54: return 0x6F; // keypad /+ case 0x55: return 0x6A; // keypad *+ case 0x56: return 0x6D; // keypad -+ case 0x57: return 0x6B; // keypad ++ case 0x58: return 0x0D; // keypad enter+ case 0x62: return 0x60; // keypad 0+ case 0x63: return 0x6E; // keypad .+ case 0x64: return 0xE2; // ISO \ |+ case 0x65: return 0x5D; // menu+ default: return 0;+ }+}++uint8_t modifierVk(int bit) {+ static constexpr uint8_t kVk[8] = {0x11, 0x10, 0x12, 0x5B, 0x11, 0x10, 0x12, 0x5C};+ return bit >= 0 && bit < 8 ? kVk[bit] : 0;+}++} // namespace xc::inputdiff --git a/src/stream/input_packet.cpp b/src/stream/input_packet.cppindex 3f129e9..b564a10 100644--- a/src/stream/input_packet.cpp+++ b/src/stream/input_packet.cpp@@ -90,6 +90,38 @@ std::vector<uint8_t> gamepadReport(uint32_t sequence, double timestampMs, constreturn b;}+std::vector<uint8_t> mouseReport(uint32_t sequence, double timestampMs, const std::vector<MouseFrame>& frames) {+ size_t count = std::min<size_t>(frames.size(), 30);+ auto b = header(kReportMouse, sequence, timestampMs, kHeaderSize + 1 + count * 18);+ size_t o = kHeaderSize;+ put8(b, o++, static_cast<uint8_t>(count));+ for (size_t i = 0; i < count; ++i) {+ const MouseFrame& f = frames[i];+ put32(b, o, static_cast<uint32_t>(f.dx));+ put32(b, o + 4, static_cast<uint32_t>(f.dy));+ put32(b, o + 8, static_cast<uint32_t>(f.wheelX));+ put32(b, o + 12, static_cast<uint32_t>(f.wheelY));+ put8(b, o + 16, f.buttons);+ put8(b, o + 17, 0); // 0: relative movement+ o += 18;+ }+ return b;+}++std::vector<uint8_t> keyboardReport(uint32_t sequence, double timestampMs, const std::vector<KeyFrame>& frames) {+ size_t count = std::min<size_t>(frames.size(), 30);+ auto b = header(kReportKeyboard, sequence, timestampMs, kHeaderSize + 1 + count * 3);+ size_t o = kHeaderSize;+ put8(b, o++, static_cast<uint8_t>(count));+ for (size_t i = 0; i < count; ++i) {+ put8(b, o, 2); // a virtual-key code (1 known, 2 VKey, 3 app command)+ put8(b, o + 1, frames[i].pressed ? 1 : 0);+ put8(b, o + 2, frames[i].vk);+ o += 3;+ }+ return b;+}+bool parseVibration(const uint8_t* d, size_t len, Vibration& out) {if (len < 13 || d[0] != kReportVibration) return false;out.gamepadIndex = d[3];diff --git a/src/stream/input_packet.h b/src/stream/input_packet.hindex 19618d6..5cdeff5 100644--- a/src/stream/input_packet.h+++ b/src/stream/input_packet.h@@ -15,6 +15,8 @@ enum ReportType : uint16_t {kReportGamepad = 2,kReportClientMetadata = 8,kReportServerMetadata = 16,+ kReportMouse = 32,+ kReportKeyboard = 64,kReportVibration = 128,};@@ -48,6 +50,21 @@ struct GamepadFrame {bool operator==(const GamepadFrame&) const = default;};+// Mouse movement since the last frame (relative), in the browser's units+// (the web client sends twice PointerEvent.movementX/Y), the wheel's steps+// and the buttons (1 left, 2 right, 4 middle, 8 back, 16 forward).+struct MouseFrame {+ int32_t dx = 0, dy = 0, wheelX = 0, wheelY = 0;+ uint8_t buttons = 0;+};++// A key going down or up, as a Windows virtual-key code (what the web+// client sends from KeyboardEvent.keyCode).+struct KeyFrame {+ uint8_t vk = 0;+ bool pressed = false;+};+struct Vibration {uint8_t gamepadIndex = 0;// 0..100 percent.@@ -70,6 +87,10 @@ std::vector<uint8_t> clientMetadataReport(uint32_t sequence, double timestampMs,// 30 per report).std::vector<uint8_t> metadataReport(uint32_t sequence, double timestampMs, const std::vector<FrameMetadata>& frames);std::vector<uint8_t> gamepadReport(uint32_t sequence, double timestampMs, const GamepadFrame& frame);+// Native mouse and keyboard, for the titles that take them (at most 30+// frames per report).+std::vector<uint8_t> mouseReport(uint32_t sequence, double timestampMs, const std::vector<MouseFrame>& frames);+std::vector<uint8_t> keyboardReport(uint32_t sequence, double timestampMs, const std::vector<KeyFrame>& frames);// Server -> client reports. Return false when `data` is another report type.bool parseVibration(const uint8_t* data, size_t len, Vibration& out);diff --git a/src/stream/stream_session.cpp b/src/stream/stream_session.cppindex 32f05df..23b7933 100644--- a/src/stream/stream_session.cpp+++ b/src/stream/stream_session.cpp@@ -710,6 +710,16 @@ bool StreamSession::start(std::string& err) {}bool StreamSession::isOpen() const { return impl_->open; }+void StreamSession::sendMouse(const MouseFrame& frame) {+ if (!impl_->open) return;+ Impl::sendBinary(impl_->input, mouseReport(impl_->inputSequence++, impl_->nowMs(), {frame}));+}++void StreamSession::sendKeys(const std::vector<KeyFrame>& keys) {+ if (!impl_->open || keys.empty()) return;+ Impl::sendBinary(impl_->input, keyboardReport(impl_->inputSequence++, impl_->nowMs(), keys));+}+void StreamSession::sendGamepad(const GamepadFrame& frame) {if (!impl_->open) return;Impl& d = *impl_;diff --git a/src/stream/stream_session.h b/src/stream/stream_session.hindex 911a1f6..57ace8d 100644--- a/src/stream/stream_session.h+++ b/src/stream/stream_session.h@@ -88,6 +88,9 @@ public:void sendGamepad(const GamepadFrame& frame);// Voice chat: sends an encoded Opus frame to the stream server (RTP @ 48 kHz).void sendAudio(const uint8_t* opus, size_t size, uint32_t timestamp);+ // Native mouse and keyboard (games that take them).+ void sendMouse(const MouseFrame& frame);+ void sendKeys(const std::vector<KeyFrame>& keys);// Touch input on or off (off at the start).void setTouchEnabled(bool on);// A controller at `index` (1..3; 0 is attached at the start) came or went.diff --git a/tests/test_main.cpp b/tests/test_main.cppindex de0020b..3c63568 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -21,6 +21,7 @@#include "util/json.h"#include "auth/auth_manager.h"#include "stream/h264_receiver.h"+#include "input/kbm.h"#include "platform/platform.h"#include "auth/msa.h"#include "ui/image_cache.h"@@ -903,6 +904,36 @@ static void testAudioDecoderEmptyPacket() {CHECK(!out.empty());}+// Native mouse and keyboard reports: header, counts and fields.+static void testMouseKeyboardReports() {+ using namespace xc::stream;+ auto m = mouseReport(7, 1.0, {MouseFrame{-3, 5, 0, 1, 1}});+ CHECK(m.size() == 14 + 1 + 18);+ CHECK(m[0] == 32 && m[1] == 0 && m[2] == 7); // type 32 (mouse), sequence 7+ CHECK(m[14] == 1); // one frame+ CHECK(m[15] == 0xFD && m[16] == 0xFF && m[17] == 0xFF && m[18] == 0xFF); // dx -3, little-endian+ CHECK(m[19] == 5 && m[27] == 1 && m[31] == 1 && m[32] == 0); // dy, wheel Y, buttons, relative+ auto k = keyboardReport(8, 1.0, {KeyFrame{0x41, true}, KeyFrame{0x41, false}});+ CHECK(k.size() == 14 + 1 + 6);+ CHECK(k[0] == 64 && k[14] == 2);+ CHECK(k[15] == 2 && k[16] == 1 && k[17] == 0x41);+ CHECK(k[18] == 2 && k[19] == 0 && k[20] == 0x41);+}++// USB keyboard: HID usages and modifier bits to Windows virtual keys.+static void testHidToVk() {+ using xc::input::hidToVk;+ CHECK(hidToVk(0x04) == 'A' && hidToVk(0x1D) == 'Z');+ CHECK(hidToVk(0x1E) == '1' && hidToVk(0x26) == '9' && hidToVk(0x27) == '0');+ CHECK(hidToVk(0x28) == 0x0D && hidToVk(0x29) == 0x1B && hidToVk(0x2C) == 0x20);+ CHECK(hidToVk(0x3A) == 0x70 && hidToVk(0x45) == 0x7B); // F1, F12+ CHECK(hidToVk(0x4F) == 0x27 && hidToVk(0x52) == 0x26); // right, up+ CHECK(hidToVk(0x59) == 0x61 && hidToVk(0x62) == 0x60); // keypad 1, 0+ CHECK(hidToVk(0x00) == 0 && hidToVk(0xE0) == 0);+ CHECK(xc::input::modifierVk(0) == 0x11 && xc::input::modifierVk(1) == 0x10 && xc::input::modifierVk(2) == 0x12);+ CHECK(xc::input::modifierVk(5) == 0x10 && xc::input::modifierVk(7) == 0x5C);+}+int main() {testReport();testCrashGuard();@@ -930,6 +961,8 @@ int main() {testJson();testUrl();testInputPacket();+ testMouseKeyboardReports();+ testHidToVk();testTeredo();if (g_failures) {std::fprintf(stderr, "%d failure(s)\n", g_failures);