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

查看:117
本文介绍了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天全站免登陆