来自 Windows 的低级键盘输入 [英] Low level keyboard input from Windows

查看:25
本文介绍了来自 Windows 的低级键盘输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些 win32 调用可用于从 Windows 服务全局检测按键事件(不仅针对 1 个窗口,我希望每次按下按键时都收到一条消息)?

What win32 calls can be used to detect key press events globally (not just for 1 window, I'd like to get a message EVERY time a key is pressed), from a windows service?

推荐答案

你想使用 Win32 Hooks.特别是键盘钩子.

You want to use Win32 Hooks. In particular a keyboard hook.

你可以阅读更多关于这里

你想要的钩子类型是 WH_KEYBOARD,你可以通过 Win32 API SetWindowsHookEx 设置它.

The type of hook you want is WH_KEYBOARD and you can set it via the Win32 API SetWindowsHookEx.

基本上,每次在任何应用程序系统范围内按下一个键时,windows 都会调用您创建的 dll 中的一个函数.

Basically windows will call a function in a dll that you create everytime a key is pressed in any application system wide.

钩子会调用你的函数,它会有这个接口:

The hook will call your function which will have this interface:

LRESULT CALLBACK KeyboardProc(      
    int code,
    WPARAM wParam,
    LPARAM lParam
);

在此处了解有关此回调的更多信息.

使用 windows 挂钩,您不仅可以跨所有进程跟踪系统范围的事件,还可以过滤它们并完全停止它们.

With windows hooks you can not only track system wide events across all processes, but you can also filter them and stop them altogether.

这篇关于来自 Windows 的低级键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆