您将如何制作一个有条件地阻止输入的 Windows 应用程序?

发布于 2024-08-09 01:00:25 字数 484 浏览 10 评论 0原文

您可能听说过 PawSense,这是一个仅适用于 Windows 的实用程序,可以在认为有效时阻止输入的击键键盘上有一只猫或其他动物正在输入无意义的输入,例如“zlxkkkkkkkk;”。这似乎是我在业余时间做的一个有趣的项目,但我想知道实现它的一些细节。

我认为我可以完成其中的模式识别部分,无论是使用硬编码启发式还是使用某种模式识别算法(我之前已经接触过并且感觉很舒服)。我的问题是关于系统编程方面的问题以及如何阻止输入的逻辑。

您需要让您的应用程序观察输入,并在检测到猫打字时提出挑战。您会保留最近击键的缓冲区,并且仅在非猫打字时才让它们通过吗?或者,如果发生猫输入,您会在阻止输入之前只允许少量数字通过吗?您想要使用的实际逻辑是什么?

至于在 C# 中阻止输入的实际机制,该网站上还有其他问题。重申一下,我的问题是您将使用什么逻辑来检测和阻止猫打字。

You may have heard of PawSense, a Windows-only utility that prevents keystrokes from being entered when it believes there is a cat or other animal on the keyboard typing nonsense input like "zlxkkkkkkkk;". It seems like a fun project to do in my spare time but I was wondering about some details of implementing it.

I think I could do the pattern recognition part of it, either with hard-coded heuristics or using some kind of pattern recognition algorithm (which I've been exposed to before and feel comfortable with). My question is about the systems programming side of things and the logic for how you'd block input.

You'd need to have your application observe input and present a challenge if you detect cat typing. Would you keep a buffer of recent keystrokes and only let them through if it was non-cat typing? Or if there was cat typing occurring, would you only let a small number through before blocking input? What would be the actual logic you'd want to use?

As for the actual mechanics of blocking input in, say, C#, there are other questions about on this site. My question, to reiterate, is what logic you'd use to detect and block cat typing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半世晨晓 2024-08-16 01:00:25

我会等到我认为键盘上有一只猫,然后阻止输入,因为缓冲区可能会出现问题。

例如,如果我正在打字,并且快速切换窗口,打字,您将如何确定击键应该在哪里?

保持它需要的简单性。

I would wait until I think there is a cat on the keyboard, then block the input, as a buffer can be problematic.

For example, if I am typing, and switching windows quickly, typing, how would you determine where the keystrokes should be?

Keep it as simple as it needs to be.

甚是思念 2024-08-16 01:00:25

您需要考虑引入WIN32 系统范围的挂钩。这篇MSDN 文章涵盖了此基础知识(注意它指定了两个应用程序)或线程级挂钩和系统范围挂钩)。

一旦您理解了这一点,您将需要捕获几个与键盘相关的消息,当然是 WM_KEYUP,还有一些其他 WM_KEYxxxx 消息,具体取决于您的需要)。

然后,您需要引入决定击键是否有效或乱码的逻辑,以及传递消息(以便它们最终可以渗透到具有焦点的应用程序)或忽略它们。

You need to look into introducing a WIN32 systemwide hook. This MSDN article covers the basics of this (attention it specifies both application or thread level hooks and system-wide hooks).

Once you understand that, you'll need to catch several keyboard related messages, WM_KEYUP for sure, a few other WM_KEYxxxx messages as well, depending on your needs).

You'll then need to introduce the logic which decides whether keystrokes are valid or gibberish, and either pass-on the messages (so they can eventually trickle down to the application which has focus) or ignore them.

别低头,皇冠会掉 2024-08-16 01:00:25

在对此一无所知的情况下,我会首先根据按下按键的时间长短而不是实际按下的按键来判断,认为动物不会简单地按下一个键并很快松开,然后再按下另一个键,等等。但更有可能在一组按键上暂停。

因此,如果您可以简单地计算按键时间,我认为这可能会起作用。

Without knowing anything about this, I would start out basing it on how long keys are pressed and not on what keys are actually pressed, thinking that an animal is not going to simply press one key and release it very quickly, then another, etc. but is more likely to pause on a set of keys.

So if you can simply time keypresses, I think that might work.

帥小哥 2024-08-16 01:00:25

思考负荷。我会从以下内容开始:

  1. 等待没有用户活动,例如:2 分钟时间。
  2. 启动您的应用程序
  3. 聆听键盘敲击
  4. 如果字典中存在键入的键,则匹配
  5. 该键 在六或七之后阻止键盘。

Thinking out load. I would start with something like following:

  1. Wait for no user activity for like: 2 minutes time.
  2. Start your app
  3. Listen to keyboard hits
  4. Match the typed keys if it exists in the dictionary
  5. Block the keypad after six or seven.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文