Re: Detecting a keydown or key up.
Re: Detecting a keydown or key up.
- Subject: Re: Detecting a keydown or key up.
- From: Stan Cleveland <email@hidden>
- Date: Tue, 02 Aug 2011 13:03:28 -0700
On Aug 2, 2011, at 8:25 AM, Zavatone, Alex wrote:
> I've been looking around with google and wonder if, in this modern age, we still have to monkey around to detect a key's state? Particularly the modifier keys?
Hi Alex,
Here's another option, if you don't mind the overhead of a shell call. The checkModifierKeys shell command by Stefan Klieme can be downloaded from http://www.klieme.ch/pub/checkModifierKeys.zip. You can install it anywhere, if you include its full POSIX path in your 'do shell script' command (as shown below). Or, if you put it within one of the paths from the shell's $PATH environment variable* (if you grok that), you can just use 'checkModifierKeys'.
Here's a sample of usage:
set modKeyDown to modifierKeyDownTest("option")
--> true
on modifierKeyDownTest(theKey)
set utilityPath to "/usr/local/bin/checkModifierKeys" -- note use of full path
set modKeyDown to do shell script (utilityPath & " " & theKey)
return (modKeyDown as integer) as boolean
end modifierKeyDownTest
It only checks for modifier keys. Besides "option", you can test for "shift", "cmd", "control", and "capslock" or combinations thereof. For example:
set modKeyDown to modifierKeyDownTest("cmd option")
The above line will return 'true' if both keys are held down and 'false' if one or neither is held down.
It might not be what you're looking for, but thought I'd mention it anyway.
Stan C.
_______
*To set up the 'do shell script' environment variable, you would create a created property list file at /Users/you/.MacOSX/environment.plist and define a PATH child property with a value of something like "/opt/local/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin".
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden