windows 在 Window 服务中捕获 KeyPress 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3595993/
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
Capturing KeyPress Event in WIndow Service
提问by Shantanu Gupta
I am trying to create a window service to create a small keylogger application. I am new to Windows services and my sole purpose is to learn.
我正在尝试创建一个窗口服务来创建一个小的键盘记录器应用程序。我是 Windows 服务的新手,我的唯一目的是学习。
How can I obtain all the events that are available in Winforms, but in a Windows service?
如何获取 Winforms 中可用但在 Windows 服务中可用的所有事件?
I've tried searching on Google, but I'm unable to find out how to do this. I'm getting many references to keyhook DLLs.
我试过在谷歌上搜索,但我无法找到如何做到这一点。我收到了很多对 keyhook DLL 的引用。
回答by t0mm13b
Windows Services are not form based therefore you cannot do it that way.... Have a look herefor an example of how to create a Windows Service that kills other windows.
Windows 服务不是基于表单的,因此您不能那样做....在这里查看如何创建杀死其他窗口的 Windows 服务的示例。
A window service is not an ideal spot to place a form on... think of a daemon under Linux/Unix variants - they do not have a graphical display nor interact with the user as such and hence would be 'headless' for want a word for it as there's no interaction whatsoever, and furthermore, a service would be running under a system service account....
窗口服务不是放置表单的理想位置……想想 Linux/Unix 变体下的守护进程——它们没有图形显示,也没有与用户交互,因此如果想要一个“无头”因为没有任何交互,而且服务将在系统服务帐户下运行......
Speaking of Keyloggers, it does not work like that - you need to hook into the global keyboard hook and intercept the keys, an example of such a thing is here.
说到键盘记录器,它不是那样工作的——你需要钩入全局键盘钩子并拦截键,这样的事情的一个例子是here。
But then the question will arise for what purpose, gather data, etc - possibly AV's will flag them as malware... If you are doing it for yourself - that's good...but to maliciously place it on another computer without that user knowing about it is very iffy and could end up in court for invasion of privacy, in terms of local laws etc.
但是随后会出现问题是出于什么目的,收集数据等 - 可能 AV 会将它们标记为恶意软件...关于它是非常不确定的,最终可能会因侵犯隐私而上法庭,根据当地法律等。