look at this pages
http://www.macosxhints.com/article.php?story=20040330161158532
http://bbs.applescript.net/viewtopic.php?id=16030
Also I run this in one of my scripts to run part of my script if there is no keys pressed for a set period of time.
i.e I am not using the mac
I can not remember where I found my part but it may help you do a search.
The part of AS below is put with in a idle handler
-- idle handler and other parts of script here which runs every 30 seconds or so -----
set idletime to do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'"
set idletime to idletime as string
set idletime to idletime as integer
if idletime is greater than 110 then -- 110 = 1 minute and 50 seconds without a key being pressed
---- your action here -----
else
---- your other action here -----
you could try and google
“ioreg -c IOHIDSystem applescript”