Search code examples
c#windowspattern-recognition

How would you make a Windows application that conditionally blocks input?


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.


Solution

  • 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.