views:

516

answers:

4

I keep typing "t eh" instead of " the" which is, of course, annoying in the amount of time it takes me to correct myself.

The obvious answer is "Learn to type, noob!" or at least to type more slowly and/or more correctly. This error is frighteningly consistent so it appears I've trained my muscle memory for that pattern already.

But I'm wondering if it's possible to write a small, windows portable script or application that, when it detects the incorrect sequence, backspaces and corrects it automatically at a layer where it would apply to any keyboard input.

  • Does C# have access to that layer of the OS that intercepts keypresses systemwide?
  • Will I run into UAC issues with Vista?
  • Am I re-inventing the wheel (ie, are there open source tools I can modify or use out of the box)?

In DOS this sort of thing was quite easy and one could make TSRs (Terminate and Stay Resident) programs that would, for instance, give you a calculator onscreen with a special keypress. Not to mention the many, many practical joke programs based on this concept (dial "M" for monster!)...

I would, of course, never suggest such a utility could be used that way for co-workers...

+3  A: 

On windows you could use AutoHotKey. That allows you to create little scripts or macros to automate and correct things like mistypes.

One use was posted on lifehacker which took the common mistyped words and corrected them. It is at http://lifehacker.com/192506/download-of-the-day-universal-autocorrect


UPDATE Per Comment: This is Free software and windows only as far as I know.

The above script is just an example of what it can do. There are a slew of scripts available at AutoHotkeys Site

Rob Haupt
Thanks! Might mention that this is C++ and is open source.
Adam Davis
+1  A: 

I suggest AutoHotKey. If you've never used it before, have a quick read of the tutorial: http://www.autohotkey.com/docs/Tutorial.htm

The feature you are looking for is called "hotstrings." http://www.autohotkey.com/docs/Hotstrings.htm

In your case, your script would look something like:

::teh::the

That's it! Add other things you want corrected on additional lines. AutoHotkey scripts can be compiled so you don't have to install AutoHotKey on all of your machines.

It's a very cool program. It's primary use (for making custom hotkeys) rocks! These scripts are system wide so you'll also probably want to make a hotkey to be able to turn them off too!

EDIT: In a comment, it was mentioned that he actually types "t eh" (with a space in it) and I wondered if something additional would be needed for it to work. I just tested it and it works fine. Just install autohotkey, and create a file with the .AHK extension. In that file put in the following line

::t eh::the

and save the file. Then double-click on the AHK file to load AutoHotKey with your script (you'll see a green square in your system tray to let you know it is running). It should work fine!

TorgoGuy
I don't actually type "teh" I type "t eh" - in other words, the sentence would be "I amt eh King!" rather than "I am the King!" Yes, it's odd.
Adam Davis
Since there is a space in that, you'll also have to play around with AutoHotKey's ending characters option (see the hotstrings page I linked to above) because normally you can't have a space in the middle of a hotstring.
TorgoGuy
I figured it wasn't going to be trivially straightforward...
Adam Davis
I updated my answer. As it turns out it is trivial. Just add the space into the "teh" and it works fine. You don't have have to mess with the ending characters option. I tested it.
TorgoGuy
A: 

Yes, you can use pinvoke commands from C# to intercept the low-level os commands. I recommend you take a look at http://www.pinvoke.net. The coding isn't easy but it does work.

Jason Irwin
I was all excited that this could be done in C#, but the link doesn't go directly to a page that shows the low level commands. Can you give more guidance here?
Adam Davis
Is this the right area? http://www.pinvoke.net/default.aspx/user32/SetWindowsHookEx.html
Adam Davis
Adam, sorry for not posting more information. You found the correct page. Below are a few useful links: http://msdn.microsoft.com/en-us/magazine/cc188966.aspxhttp://www.codeguru.com/cpp/w-p/system/keyboard/article.php/c5699http://blogs.msdn.com/toub/archive/2006/05/03/589423.aspx
Jason Irwin
the last link by toub is the most useful.
Anonymous Type
I don't understand the downvote. This is a developer site, and I provided information on writing code to solve the original problem...
Jason Irwin
A: 

I suggest learning to type more slowly. I also suffer from "teh" and "ahve" in part due to autocorrect giving me the leniency. If you forced yourself to retrain then you would not be at a disadvantage when using someone else's machine.

Not to mention the unfortunate event when you need to write "t eh" and are being prevented by an overzealous 'corrector'.

Karl