[comp.sys.mac.programmer] mac programming question

dk1y+@andrew.cmu.edu (David Kosmal) (04/15/89)

I have a mac programming question concerning some lower level hardware stuff,
and I was wondering if anyone out there could help me:

I am interested in developing a simple program for a psychology experiment that
will measure the time interval between a the appearance of a display on the
screen and when the viewer presses a key.  This time interval must be measured
within 1/100th of a second.

Can it be done with a standard mac keyboard?  If so, were are some of the low
level entry points that I can use to do this?  I have looked through various
parts of Inside Macintosh, but still I am not sure what exactly happens when a
key is pressed.  Ideally there would be some kind of interrupt that I could
catch.

Also, can I use any of the system timers to measure the interval?  Again, Inside
Macintosh is not precise on this.

I know the basics of the Macintosh toolbox and am very familiar with the 68000.
Any help, including books to look at, would be appreciated.

Thanks,

David Kosmal

oster@dewey.soe.berkeley.edu (David Phillip Oster) (04/15/89)

In article <UYFX8Hy00Xo=Q11UwL@andrew.cmu.edu> dk1y+@andrew.cmu.edu (David Kosmal) writes:
>I am interested in developing a simple program for a psychology experiment that
>will measure the time interval between a the appearance of a display on the
>screen and when the viewer presses a key.  This time interval must be measured
>within 1/100th of a second.
You can measure time this short using the Time manager, (documented in
Inside Mac Vol 4.) Be sure to calibrate it. It is documented as giving
you a time interval resolution of .01 seconds, but my tests showed that at
least on my machine it was more like .011 seconds.
Another problem: I believe that the keyboard and mouse button are only
polled at most 60 times a second. If you want to go faster, consider using
a simple switch that changes the level of the CTS line of the serial port.
(Be sure you know what you are doing before shorting wires in the serial
port!)  Thunderscan works by toggling the handshaking wire: the rate it
toggles the wire is porportional to how much light is being reflected back
into the light sensor.

denbeste@bgsuvax.UUCP (William C. DenBesten) (04/17/89)

From article <UYFX8Hy00Xo=Q11UwL@andrew.cmu.edu>, by dk1y+@andrew.cmu.edu (David Kosmal):
> ... measure the time interval between a the appearance of a display on the
> screen and when the viewer presses a key.  This time interval must be measured
> within 1/100th of a second.

Take a look at the Toolbox Event manager in Inside Macintosh.  The
event record that is returned includes a field, 'when', that tells
when the event happened in 60ths of a second since the computer was
turned on.  Keypresses are returned as events.

I would strongly recommend going with 60th of a second resolution,
rather than monkeying around with low level stuff. This way you won't
have to make any funny patches that could affect future compatibility.

You can call TickCount() to find out the current 60th of a second.

-- 
 William C. DenBesten
 denbeste@bgsu.edu
denbesten@bgsuopie.bitnet

jb28+@andrew.cmu.edu (Jeffrey Joseph Barbose) (04/19/89)

David,

I'm not really sure if this is what you're looking for, but you'll be able to
answer some of your questions by reading the Macintosh Family Hardware Reference
put out by Apple.  Copies are usually available at mall bookstores.  Topics
include data and address bus transmissions and keystroke processing.

Hope this helps,


Jeff

rmf517@uxf.cso.uiuc.edu (04/20/89)

> > ... measure the time interval between a the appearance of a display on the
> > screen and when the viewer presses a key.  This time interval must be
> > measured
> > within 1/100th of a second.
> 
> Take a look at the Toolbox Event manager in Inside Macintosh.  The
> event record that is returned includes a field, 'when', that tells
> when the event happened in 60ths of a second since the computer was
> turned on.  Keypresses are returned as events.
 
Take a look at the Time Manager Routines in IM IV.  It sounds like you could
have a function called every 1/100 of a sec. and check for a KeyDown.
Then you could get better resoultion then 60th of a sec.

Bob Frank - struggling undergrad @ the UofI