【问题标题】:How do I intercept Windows key under Windows 7?如何在 Windows 7 下拦截 Windows 密钥?
【发布时间】:2010-07-17 05:53:32
【问题描述】:

您好,

here 所述,我已经实现了一个低级键盘挂钩。这在 WinXP 下运行良好。 问题是,在Windows 7下,左右windows键不再被拦截。

非常感谢任何有关如何在 Windows 7 下重新获取这些密钥的建议!

干杯,

罗尼

【问题讨论】:

  • Windows 键本身,还是您尝试注册全局热键?如果是后者,您可以直接致电RegisterHotKey。但是请注意,所有使用 Windows 键的热键都保留供 Windows 使用,因此您的里程可能会有所不同。

标签: c++ windows-7 keyboard-hook


【解决方案1】:

我已经构建了一个库,因为在许多情况下正常的挂钩对我不起作用,所以我构建了一个 c 库来与底层的过滤器驱动程序进行通信,以完成设备输入拦截的​​工作。以下是如何使用此库捕获 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查看更多文档。

【讨论】:

  • 我有一些我想挂接/拦截的触摸屏的设备 vid 和 pid。你的拦截库+驱动程序可以用来捕捉那些吗?还是仅限于鼠标和键盘?
  • @phyatt 目前仅限于鼠标和键盘抱歉。
  • 不用担心。感谢您的回复。
【解决方案2】:

查看适用于 Windows 7 的 Win Kernel SDK 并编写一个“驱动程序”来实现这一点。

【讨论】:

  • 谢谢,我会查一下。不过,我希望有一个不那么痛苦的解决方案......
猜你喜欢
  • 1970-01-01
  • 2015-06-18
  • 2020-02-21
  • 1970-01-01
  • 2013-10-04
  • 2020-02-08
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
相关资源
最近更新 更多