windows 捕获所有键盘输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6630623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:21:45  来源:igfitidea点击:

Capture All Keyboard Input

c++windows

提问by David Heffernan

First off, I know this could be used for a keylogger. I'm not going for that, I'm looking to make an application that listens for custom key combinations just to automate a few really annoying tasks.

首先,我知道这可以用于键盘记录器。我不打算这样做,我正在寻找一个应用程序来侦听自定义组合键只是为了自动化一些非常烦人的任务。

Is there some way to capture all input from the keyboard?

有没有办法从键盘捕获所有输入?

回答by David Heffernan

You appear to be looking for RegisterHotKey().

您似乎正在寻找RegisterHotKey().

I don't think you want to hook all keyboard input. You simply want an app with a hidden window listening for WM_HOTKEY. I don't think you even need to write it yourself. There are a lots of utilities that will do it for you and let you associate system-wide hot keys with actions of your specification, e.g. AutoHotKey.

我认为您不想挂钩所有键盘输入。您只需要一个带有隐藏窗口的应用程序来监听WM_HOTKEY. 我认为你甚至不需要自己写。有很多实用程序可以为您完成此操作,并让您将系统范围的热键与您的规范操作相关联,例如AutoHotKey

回答by Andriy Tylychko

to capture keyboard input even when your application is not focused, you need to use windows hook, WH_KEYBOARDone. It should be implemented as a DLL to be injected into all processes. Example here

即使您的应用程序没有获得焦点,也要捕获键盘输入,您需要使用windows hookWH_KEYBOARD之一。它应该被实现为一个 DLL,以注入到所有进程中。示例在这里