windows 在后台创建一个进程来听键盘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8494435/
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
Creating a Process in the background that will listen to keyboard
提问by Giora Ron Genender
I have a project that runs in the background in a different process, I want it to be able to react to keyboard everywhere, for example I run the project, and afterwards I do other stuff in the computer such as browsing, facebook, watching movies etc.., and every time I press F9 I want my project to show up. Same as how you press a combination of keys to invoke Babylon... I want to implement it in C#, I have no idea how to begin.
我有一个项目在不同的进程中在后台运行,我希望它能够在任何地方对键盘做出反应,例如我运行该项目,然后我在计算机上做其他事情,例如浏览,facebook,看电影等等,每次我按 F9 时,我都希望我的项目出现。和按组合键调用 Babylon 的方式一样...我想用 C# 实现它,我不知道如何开始。
回答by Matteo Italia
You can register a hotkey with the RegisterHotKey
API function. You can see an example of its usage from C# here.
您可以使用RegisterHotKey
API 函数注册热键。您可以在此处从 C# 中查看其用法示例。
回答by Davide Piras
I think you need to write a system-wide keyboard hook, check here for details:
我认为您需要编写一个系统范围的键盘钩子,请在此处查看详细信息:
https://stackoverflow.com/a/1764434/559144
https://stackoverflow.com/a/1764434/559144
How do I grab events for all applications? An example system-wide hook.