如何在Windows 7下拦截Windows密钥?

发布于 2024-09-10 06:32:10 字数 255 浏览 4 评论 0原文

您好,

我已经实现了一个低级键盘挂钩,如此处。这在WinXP下工作得很好。 问题是,在 Windows 7 下,左右 Windows 键不再被拦截。

任何有关如何在 Windows 7 下重新捕获这些密钥的建议,我们将不胜感激!

干杯,

罗尼

Greetings,

I've implemented a low-level keyboard hook as described here. This works fine under WinXP.
Problem is, under Windows 7 the left and right windows keys are no longer intercepted.

Any suggestions as to how to recapture these keys under Windows 7 greatly appreciated!

Cheers,

Rony

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

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

发布评论

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

评论(2

随梦而飞# 2024-09-17 06:32:10

我构建了一个库,因为在很多情况下正常的挂钩对我来说不起作用,所以我构建了 ac 库来与底层的过滤器驱动程序进行通信,以完成设备输入拦截的​​工作。以下是如何使用此库捕获 Windows 密钥的示例:

#include <iostream>
#include <interception.h>
#include "utils.h" // for process priority control

const InterceptionKeyStroke windows_key_down = {91, INTERCEPTION_KEY_E0 | INTERCEPTION_KEY_DOWN};
const InterceptionKeyStroke windows_key_up = {91, INTERCEPTION_KEY_E0 | INTERCEPTION_KEY_UP};

bool operator == (const InterceptionKeyStroke &left, const InterceptionKeyStroke &right)
{
    return left.code == right.code && left.state == right.state;
}

int main()
{
    using namespace std;

    InterceptionContext context;
    InterceptionDevice device;
    InterceptionStroke stroke;

    raise_process_priority();

    context = interception_create_context();

    interception_set_filter(context, interception_is_keyboard, INTERCEPTION_FILTER_KEY_ALL);

    while(interception_receive(context, device = interception_wait(context), &stroke, 1) > 0)
    {
        InterceptionKeyStroke &keystroke = *(InterceptionKeyStroke *) &stroke;

        if(keystroke == windows_key_down)
            cout << "Windows Key Down" << endl;

        if(keystroke == windows_key_up)
            cout << "Windows Key Up" << endl;

        interception_send(context, device, &stroke, 1);
    }

    interception_destroy_context(context);

    return 0;
}

该示例捕获密钥并将其发送回操作系统,但您也可以执行其他操作。

您可以在 http://oblita.com/Interception 查看更多文档。

I have built a library because normal hooking was not working for me in a number of cases, so I've built a c library to communicate with filter drivers under the hood to do the work of device input interception. Here's a sample of how to capture the Windows key using this library:

#include <iostream>
#include <interception.h>
#include "utils.h" // for process priority control

const InterceptionKeyStroke windows_key_down = {91, INTERCEPTION_KEY_E0 | INTERCEPTION_KEY_DOWN};
const InterceptionKeyStroke windows_key_up = {91, INTERCEPTION_KEY_E0 | INTERCEPTION_KEY_UP};

bool operator == (const InterceptionKeyStroke &left, const InterceptionKeyStroke &right)
{
    return left.code == right.code && left.state == right.state;
}

int main()
{
    using namespace std;

    InterceptionContext context;
    InterceptionDevice device;
    InterceptionStroke stroke;

    raise_process_priority();

    context = interception_create_context();

    interception_set_filter(context, interception_is_keyboard, INTERCEPTION_FILTER_KEY_ALL);

    while(interception_receive(context, device = interception_wait(context), &stroke, 1) > 0)
    {
        InterceptionKeyStroke &keystroke = *(InterceptionKeyStroke *) &stroke;

        if(keystroke == windows_key_down)
            cout << "Windows Key Down" << endl;

        if(keystroke == windows_key_up)
            cout << "Windows Key Up" << endl;

        interception_send(context, device, &stroke, 1);
    }

    interception_destroy_context(context);

    return 0;
}

The sample captures the key and send it back to the operating system, but you can do other things instead.

You can check more docs at http://oblita.com/Interception.

左耳近心 2024-09-17 06:32:10

查看适用于 Windows 7 的 Win Kernel SDK,并编写一个也可以挂钩此功能的“驱动程序”。

Take a look at the Win Kernel SDK for Windows 7 and program a "driver" that do hook this too.

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