views:

62

answers:

4

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.

+2  A: 

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.

James Black
+1  A: 

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.

JRL
+2  A: 

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.

mjv
A: 

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