I was reading through a forum post elsewhere and came upon the app this uses. I took a basic script an tested it for options and thought it may be of use to some.
It detects a modifier key (Option, Shift, etc.) down. Can be set to only detect a specific key or to report any modifier key.
(modified to include control key and explain the results better in the comments so it is self contained mostly)
------ Depends on getModKey app from Allan Craig
--- http://allancraig.net/index.php?option=com_docman&Itemid=100
-- run this in an idle handler to get keys down or in some other fashion to capture a key down when the do shell executes
-- if you append to the quoted text at the end of the 'do shell' line a space and then the mod key name (such as 'option'), it will provide a boolean result on the status of the particular mod key state
-- I have provided several keys and combinations below, notice that they are additive in nature (see the combinations with the Option key)
-- I have the log message so that you can see the numeric value of the result returned, either the key value or the boolean
set ModKeyDown to my ModKeyDownCheck()
-----
set ModKeyAlert to ""
if ModKeyDown > 1 then
if ModKeyDown = 256 then
set ModKeyAlert to "Command key pressed"
else if ModKeyDown = 512 then
set ModKeyAlert to "Shift key pressed"
else if ModKeyDown = 1024 then
set ModKeyAlert to "Caps Lock on"
else if ModKeyDown = 2048 then
set ModKeyAlert to "Option key pressed"
else if ModKeyDown = 2560 then -- note the key combinations cause addition of their values
set ModKeyAlert to "Shift & Option keys pressed"
else if ModKeyDown = 2816 then
set ModKeyAlert to "Shift, Option & Command keys pressed"
else if ModKeyDown = 3072 then
set ModKeyAlert to "Caps Lock on & Option key pressed"
else if ModKeyDown = 4096 then
set ModKeyAlert to "Control key pressed"
else if ModKeyDown = 4352 then
set ModKeyAlert to "Control and Command keys pressed"
else if ModKeyDown = 131072 then
set ModKeyAlert to "Function key pressed"
else if ModKeyDown = 133120 then
set ModKeyAlert to "Function & Option keys pressed"
end if
end if
-----
if ModKeyAlert ≠"" then
display alert ModKeyAlert
end if
-----
on ModKeyDownCheck()
set ModKeyDown to do shell script "/Library/UnixApps/getModKey"
(* use this if you wish only to monitor for Option key down:
set ModKeyDown to do shell script "/Library/UnixApps/getModKey option"
*)
set ModKeyDown to ModKeyDown as integer
log ModKeyDown
-- set ModKeyDown to modKeyDown as boolean
return ModKeyDown
end ModKeyDownCheck
-----
Model: MacBook (early 2009)
Browser: Safari 533.16
Operating System: Mac OS X (10.6)