Re: Intercepting every keystroke
Re: Intercepting every keystroke
- Subject: Re: Intercepting every keystroke
- From: Evan Gross <email@hidden>
- Date: Fri, 07 Mar 2003 01:40:33 -0500
On 3/6/03 8:27 PM, "Jeffrey Mattox" <email@hidden> wrote:
>
Oops -- this went to the Carbon people by mistake.
>
>
Is there a way in Cocoa (okay, or Carbon) to get every keystroke,
>
regardless of which application is active? I want to write a
>
background application that intercepts and inspects all keystrokes
>
(looking for certain strings or triggers) and then send most of them
>
on to the active application.
>
>
It must be easy -- there are several applications that do this,
>
saving the keystrokes to a file.
>
>
Jeff
>
Umm, it's not that easy, and the article at
http://www.obdev.at/developers/articles/00001.html
describes one of the MOST "not easy" ways to do this (forgive the rotten
English, but you get the drift).
If you do a little testing with most (if not all) of the apps that can
intercept keystrokes and save them to a file you'll see that they either:
- chew up a whole lot of CPU while polling for changes in the keyboard's
state, or
- simply (and easily) miss keystrokes completely if you type quickly.
There is (currently) only one Apple-supported/sanctioned way of doing this
(with any sort of accuracy and reliability) on OS X: via an Input Method
(see Apple's BasicInputMethod sample).
It's not easy to write one of these either, but at least it's supported and
(mostly, even if a bit scattered) documented.
If you don't mind missing some keystrokes and/or polling (your users may
mind the polling!) then there are other techniques that might be good enough
for your purposes.
If you're looking to somehow alter the user's keystrokes before they
actually make their way into the active application, then you're probably
best off writing an Input Method. In fact, that's the main reason for their
existence...
Hope that helps,
Evan Gross
Rainmaker Research Inc.
(Developer of Spell Catcher X, a mostly Cocoa app that uses an Input Method
for as-you-type features - see www.casadyg.com for more info).
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.