From 73f06434a43c75b3a81e31a6ed7586a14a9c7a48 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Mon, 6 Oct 2025 12:10:56 -0700 Subject: keybinds: fix repeat and long press keybinds release (#11863) --- hyprtester/plugin/src/main.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'hyprtester/plugin/src/main.cpp') diff --git a/hyprtester/plugin/src/main.cpp b/hyprtester/plugin/src/main.cpp index 2b1d443a..07f90e9f 100644 --- a/hyprtester/plugin/src/main.cpp +++ b/hyprtester/plugin/src/main.cpp @@ -120,6 +120,7 @@ class CTestMouse : public IPointer { }; SP g_mouse; +SP g_keyboard; static SDispatchResult pressAlt(std::string in) { g_pInputManager->m_lastMods = in == "1" ? HL_MODIFIER_ALT : 0; @@ -220,6 +221,30 @@ static SDispatchResult scroll(std::string in) { return {}; } +static SDispatchResult keybind(std::string in) { + CVarList data(in); + // 0 = release, 1 = press + bool press; + // See src/devices/IKeyboard.hpp : eKeyboardModifiers for modifier bitmasks + // 0 = none, eKeyboardModifiers is shifted to start at 1 + uint32_t modifier; + // keycode + uint32_t key; + try { + press = std::stoul(data[0]) == 1; + modifier = std::stoul(data[1]); + key = std::stoul(data[2]) - 8; // xkb offset + } catch (...) { return {.success = false, .error = "invalid input"}; } + + uint32_t modifierMask = 0; + if (modifier > 0) + modifierMask = 1 << (modifier - 1); + g_pInputManager->m_lastMods = modifierMask; + g_keyboard->sendKey(key, press); + + return {}; +} + APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { PHANDLE = handle; @@ -229,15 +254,22 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:alt", ::pressAlt); HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:gesture", ::simulateGesture); HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:scroll", ::scroll); + HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:keybind", ::keybind); // init mouse g_mouse = CTestMouse::create(false); g_pInputManager->newMouse(g_mouse); + // init keyboard + g_keyboard = CTestKeyboard::create(false); + g_pInputManager->newKeyboard(g_keyboard); + return {"hyprtestplugin", "hyprtestplugin", "Vaxry", "1.0"}; } APICALL EXPORT void PLUGIN_EXIT() { g_mouse->destroy(); g_mouse.reset(); -} + g_keyboard->destroy(); + g_keyboard.reset(); +} \ No newline at end of file -- cgit v1.2.3