捕获使用VB.Net所有的键盘事件 [英] Capture all keyboard events using VB.Net

查看:2187
本文介绍了捕获使用VB.Net所有的键盘事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个简单的文本框,它试图从他们的打字习惯的关键presses之间(间隔识别用户的应用程序,持续时间的关键举行,击键之间的时间,即A-> s是不是快 - > v对于某些用户来说,缩短为他人取决于打字风格)。这是远非完美,但它并正确识别的风格中等大的差异。

I've written an app with a simple textbox which attempts to identify a user from their typing habits (interval between key presses, duration key is held, time between key strokes ie a->s is quicker than a->v for some users, shorter for others depending on typing style). It's far from perfect but it does correctly identify moderate-large differences in style.

我希望以此作为安全监控的一种形式 - 如果用户的打字风格不符合公认的模式,报告到中央服务器

I'm hoping to use this as a form of security monitor - If the typing style of the user doesn't fit a recognised pattern, report to a central server.

当然,在这个测试的下一步是开始捕捉到正规军的打字习惯 - 即当浏览,应用程序之间的切换等。

Of course, the next step in testing this is to begin to capture "regular" typing habits - ie when browsing, switching between apps, etc.

我想不出什么如何做的是捕捉键盘输入的所有应用程序(不包括登录/欢迎屏幕,替代台式机,等等 - 我没有理由解析并有可能没有足够的投入反正分析)

What I can't figure out how to do is capture keyboard input for all applications (excluding the login/welcome screen, alternate desktops, etc. - I have no reason to parse that and there's probably not enough input to analyse anyway)

免责声明:是的,我知道这是以危险地接近写一个键盘记录是禁止的,但如果我想这样做,我会写在C ++中的键盘驱动程序 - 我敢肯定,这将是更精简,更容易混淆比笨重的净MSIL汇编。我毫不怀疑我会挡开这是一个键盘记录器的评论,但我已经打了一堵墙,需要问的地方...

Disclaimer: Yes, I know this comes dangerously close to writing a keylogger which is verboten but if I wanted to do that, I'd write a keyboard driver in C++ - I'm sure it would be far more streamlined and easier to obfuscate than a hulking .Net MSIL assembly. I have no doubt I'll be fending off "That's a keylogger" comments but I've hit a wall and need to ask somewhere...

我不需要的应用程序来隐藏 - 但在理想情况下希望能够(由管理员以外的安装)来捕获输入没有明确的用户确认 - 如果用户需要确认,我可以忍受的(只是)如果能够一次性的,我有一些方法来监测和报告否认。

I don't need the app to be hidden - but would ideally like to be able to capture input without explicit user confirmation (beyond installation by an admin) - If user confirmation is required, I can live with that (just) if it can be one-off and I have some way to monitor and report denials.

在NET是这甚至可能吗?通过将事件挂钩,这似乎笨重和我想像每一个关键我已经能够找到任何工作,唯一的例子,很容易出错。 - 或 - 他们查询键盘状态,以确定pressed键。这是不适合我作为一个)我需要的关键presses的精确定时,键上/下事件是必须的和b)它是讨厌的。

Is this even possible in .Net? The only examples I've been able to find either operate by adding an event hook to every key which seems clunky and I'd imagine is error-prone. -or- They poll the keyboard state to determine pressed keys. This is no good for me as a) I need exact timings of keypresses so key up/down events are a must and b) it's nasty.

这不会让我感到吃惊,如果该框架旨在明确禁止这种在这种情况下,我将不得不回落到一些非托管code提供的事件。我明明preFER使用管理code的所有道路。

It wouldn't surprise me if the framework is designed to specifically prohibit this in which case I'll have to fall back to some unmanaged code to provide the events. I'd obviously prefer to use managed code all the way.

任何帮助AP preciated。

Any help appreciated.

编辑:感谢汉斯帕桑特的答案,这是最好的资源我发现迄今:<一href="http://www.$c$cguru.com/columns/vb/article.php/c4831">http://www.$c$cguru.com/columns/vb/article.php/c4831

Thanks to Hans Passant's answer, this is the best resource I've found so far: http://www.codeguru.com/columns/vb/article.php/c4831

推荐答案

谷歌 SetWindowsHookEx函数 + WH_KEYBOARD_LL ,关键字谷歌好。这设置一个低级别的键盘钩子。它不是一个全局钩子,以便可以在一个VB.NET程序工作。

Google SetWindowsHookEx + WH_KEYBOARD_LL, keywords that google well. That sets a low-level keyboard hook. It is not a global hook so can work in a VB.NET program.

这篇关于捕获使用VB.Net所有的键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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