有效的永久性numlock keystate检查

发布于 2025-01-23 08:20:46 字数 597 浏览 1 评论 0原文

我购买了一个非常不错的键盘(Logitech G915),无论出于无关的原因,它都没有NUMLOCK指示器。因此,我正在使用Logitech的Lighting SDK使用密钥的RGB背光来制作功能。

我有一个非常简单的概念验证验证的概念:

    while (true)
    {
        if (GetKeyState(VK_NUMLOCK) & 0x1)
            LogiLedSetLightingForKeyWithKeyName(LogiLed::KeyName::NUM_LOCK, 0, 100, 100);
        else
            LogiLedSetLightingForKeyWithKeyName(LogiLed::KeyName::NUM_LOCK, 0, 0, 0);
    }

但是我认为用永久性的CPU周期循环而循环以获得如此小的功能是不好的。我应该只有时间睡觉(建议长度吗?)还是有办法睡觉,直到系统发生numlock状态变化或我只是犯错了?

此外,我还没有调查过它,但是我想将其作为背景过程或托盘应用程序(没关系,只是隐藏了),所以我想答案应该牢记该限制,如果是一个。

谢谢!

I bought a really nice keyboard (logitech G915) that for whatever inane reason doesn't have a numlock indicator. Thus, I'm using Logitech's lighting SDK to make the functionality myself using the key's rgb backlight.

I have an extremely simple console proof of concept that works:

    while (true)
    {
        if (GetKeyState(VK_NUMLOCK) & 0x1)
            LogiLedSetLightingForKeyWithKeyName(LogiLed::KeyName::NUM_LOCK, 0, 100, 100);
        else
            LogiLedSetLightingForKeyWithKeyName(LogiLed::KeyName::NUM_LOCK, 0, 0, 0);
    }

But I don't think it's good to eat up cpu cycles with a perpetual while loop for such a tiny feature. Should I just have it sleep for time (length suggested?) or is there a way to sleep until the system gets a numlock state change or am I simply going about this wrong?

Additionally, I haven't looked into it yet, but I want to make this a background process or a tray application (doesn't matter, just hidden away) so I guess answers should have that limitation in mind if it is one.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖公主 2025-01-30 08:20:46

在App Startup上,使用而不是getKeyState()获取密钥的当前状态并相应地更新灯光。

然后,使用 /code> 要安装全局挂钩每当以后按键时检测。在每个回调事件中,使用挂钩提供的状态信息,或在挂钩回调退出后立即启动异步任务以立即获取当前的密钥状态(AS getsasynckeystate()尚未更新调用回调),然后相应地更新灯。

另外,使用 raw Input api 键盘并接收 wm_input 在每个键上的窗口消息。然后获取密钥的当前状态并相应地更新灯光。

At app startup, use GetAsyncKeyState() instead of GetKeyState() to get the key's current state and update the light accordingly.

Then, use SetWindowsHookEx() to install a global WH_KEYBOARD_LL hook to detect whenever the key is pressed afterwards. On each callback event, use the state information provided by the hook, or start an asynchronous task to get the current key state immediately after your hook callback exits (as GetAsyncKeyState() has not been updated yet when the callback is called), and then update the light accordingly.

Alternatively, use the Raw Input API to monitor the keyboard and receive WM_INPUT window messages on each key press. And then get the key's current state and update the light accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文