Discussion:
Does Mac OS have windows like hooking API?
(too old to reply)
John
2004-02-28 22:33:42 UTC
Permalink
Hi -

We have a CBT product for the windows platform that uses windows system
level programming (specifically uses hooking APIs) to understand user
interactions with a program. We check if the user chose the right menu
option, entered the expected data value etc.

We are exploring if we can port some of our CBTs to the mac OS platform.
Does the mac OS have something equivalent to windows hooking APIs that we
can use to determine user actions?

Any information will be highly appreciated.

Sincerely,
John
Frederick Cheung
2004-02-29 01:02:57 UTC
Permalink
Post by John
Hi -
We have a CBT product for the windows platform that uses windows system
level programming (specifically uses hooking APIs) to understand user
interactions with a program. We check if the user chose the right menu
option, entered the expected data value etc.
We are exploring if we can port some of our CBTs to the mac OS platform.
Does the mac OS have something equivalent to windows hooking APIs that we
can use to determine user actions?
Hard to say without knowing what hooking or CBT are, but I'd guess that
Carbon Events is what you want. Most objects (eg windows, controls etc)
can have a standard handler, but you can install handlers to deal with
specific events.

Fred
Eric Albert
2004-02-29 07:39:43 UTC
Permalink
In article
<Pine.LNX.4.44.0402290101390.10359-***@kern.srcf.societies.cam.ac.uk>
,
Post by Frederick Cheung
Post by John
We have a CBT product for the windows platform that uses windows system
level programming (specifically uses hooking APIs) to understand user
interactions with a program. We check if the user chose the right menu
option, entered the expected data value etc.
We are exploring if we can port some of our CBTs to the mac OS platform.
Does the mac OS have something equivalent to windows hooking APIs that we
can use to determine user actions?
Hard to say without knowing what hooking or CBT are, but I'd guess that
Carbon Events is what you want. Most objects (eg windows, controls etc)
can have a standard handler, but you can install handlers to deal with
specific events.
And if you need to watch events in other processes, I believe there's a
Carbon Event way as of 10.3 to watch (but not modify) events that occur
in other apps.

-Eric
--
Eric Albert ***@cs.stanford.edu
http://rescomp.stanford.edu/~ejalbert/
i***@mac.com
2004-02-29 01:44:57 UTC
Permalink
Post by John
Hi -
We have a CBT product for the windows platform that uses windows system
level programming (specifically uses hooking APIs) to understand user
interactions with a program. We check if the user chose the right menu
option, entered the expected data value etc.
CBT == computer based training?
Post by John
We are exploring if we can port some of our CBTs to the mac OS platform.
Does the mac OS have something equivalent to windows hooking APIs that we
can use to determine user actions?
You can do this pretty thoroughly under OS X 10.2 and later using
the Accessibility API.

http://developer.apple.com/samplecode/Sample_Code/OS_Utilities/UIElementInspector.htm

There should also be a compiled copy of the program in the developer
download area.

You can do more limited instrumentation using Apple Events on older
Mac systems, if the program you're interested in supports it.
Neil Alexander
2004-02-29 06:38:13 UTC
Permalink
Yes, Carbon Events will get you much of the interaction you're
seeking. You may want to concentrate on 'Carbon with NIB' examples so
you can a variety of situations in a non-objective-C fashion, since I
imagine you'll want to use C++.
Uli Kusterer
2004-02-29 18:49:16 UTC
Permalink
Post by John
We have a CBT product for the windows platform that uses windows system
I'll assume CBT is Computer Based Training.
Post by John
level programming (specifically uses hooking APIs) to understand user
interactions with a program. We check if the user chose the right menu
option, entered the expected data value etc.
We are exploring if we can port some of our CBTs to the mac OS platform.
*which* MacOS platform? MacOS 9? MacOS X? I'll presume that you're only
now starting to work that you're porting to MacOS X, ok? If you're
interested in MacOS 9 or earlier, you may want to have a look at "Apple
Guide", which used to be Apple's ingenious help API and which provided a
lot of stuff for free.
Post by John
Does the mac OS have something equivalent to windows hooking APIs that we
can use to determine user actions?
It might help if you detailed what those "windows hooking APIs" do. It
might also help to tell us how much control you have over the targeted
applications. Also, is your CBT stuff running as part of that other
application, or as a separate application?

Depending on each of these, it may be as easy as just intercepting
Carbon Events or overriding the a method in NSApplication, or it may be
more complicated like using Accessibility or even injecting some code
into that other application to do one of the above things outside of
your own app. (The Extendamac mailing list and project at
http://extendamac.sourceforge.net
might be a good starting point for learning about the latter).

That being said, injecting code into other applications poses the risk
of injecting your bugs into that other application as well, so if any of
the "official" mechanisms allow doing what you want, I'd urge you to use
those instead. And if they don't, be sure to include lots of sanity
checks and give the user the option of doing without the functionality
that requires injection in case they fail. (i.e. openly, in a dialog,
not as an option that can be set using a command-line program or by
editing the preferences file).

HTH,
-- Uli
http://www.zathras.de
John
2004-03-02 08:44:10 UTC
Permalink
Thanks all of you for your valuable input. Your responses have given me
enough information on where to start my study.

Your help is highly appreciated.

John
Post by John
Hi -
We have a CBT product for the windows platform that uses windows system
level programming (specifically uses hooking APIs) to understand user
interactions with a program. We check if the user chose the right menu
option, entered the expected data value etc.
We are exploring if we can port some of our CBTs to the mac OS platform.
Does the mac OS have something equivalent to windows hooking APIs that we
can use to determine user actions?
Any information will be highly appreciated.
Sincerely,
John
Uli Kusterer
2004-03-02 13:45:09 UTC
Permalink
Post by John
Thanks all of you for your valuable input. Your responses have given me
enough information on where to start my study.
Your help is highly appreciated.
John,

it would be nice if you could post your results here. That way, someone
searching for the answer to this question (e.g. via Google groups) won't
have to ask the same question again.

I'd personally be pretty interested in learning how these Windows
"hooking" APIs correspond to the existing Mac mechanisms.

Cheers,
-- Uli
http://www.zathras.de
John
2004-03-02 15:16:42 UTC
Permalink
OK, I will. It might be a little while though :)

John.
Post by Uli Kusterer
Post by John
Thanks all of you for your valuable input. Your responses have given me
enough information on where to start my study.
Your help is highly appreciated.
John,
it would be nice if you could post your results here. That way, someone
searching for the answer to this question (e.g. via Google groups) won't
have to ask the same question again.
I'd personally be pretty interested in learning how these Windows
"hooking" APIs correspond to the existing Mac mechanisms.
Cheers,
-- Uli
http://www.zathras.de
Paul
2004-03-05 19:29:31 UTC
Permalink
Windows Hooking for Mac guys (from a Mac guy who had to learn it)

Windows hooks work on the basis of a function getting called with an event
of some type, taking some sort of action, then passing the event to the next
hook. Some allow modifying or deleting the event, others only let you see it
as it goes by.

There are several different types of hooks. They differ in which events they
receive and when, what data is available, and what can be done with the
event. CBT Hooks (Computer Based Training) tend to be the most useful in
most cases, since they cover a wide range of events.

Any application can install a hook local to itself. The process is fairly
similar to the Mac trap patching except that it patches an event instead of
an API. This type of hook ONLY sees events inside an application'e process
space.

A global hook affects ALL processes on the machine that are started AFTER
the hook is installed. These have to be located in a DLL: once the hook
function (exported from the DLL) is installed, the DLL will automatically
load into every new process and be applied there. A global hook can be
installed or removed by any application. The closest Mac equivalent is the
jGNE Filter technique from the good old days.

I recently used hooks to implement a popup blocker for IE: a small app was
launched, loaded the DLL and applied the hook; every instance of IE
thereafter was affected. The hook caught (among other things) window
creation events and decided whether the window was a popup that needed to be
deleted before appearing (harder than it sounds!) or a legitimate window.
The DLL's init code is called every time it links to a new process, so I
could check for IE and disable the hook for other applications. There is
also a way to share memory between different processes using the hook DLL,
so they can talk to each other.

Buggy hooking can destroy the stability of the entire system, and there is
an obvious impact on system performance if too many are installed or too
much processing is done.

Search MSDN.microsoft.com for more information. Incidentally, hooks aren't
directly supported under .NET for the same reason OS X doesn't have trap
patching.
Post by Uli Kusterer
Post by John
Thanks all of you for your valuable input. Your responses have given me
enough information on where to start my study.
Your help is highly appreciated.
John,
it would be nice if you could post your results here. That way, someone
searching for the answer to this question (e.g. via Google groups) won't
have to ask the same question again.
I'd personally be pretty interested in learning how these Windows
"hooking" APIs correspond to the existing Mac mechanisms.
Cheers,
-- Uli
http://www.zathras.de
Loading...