Checking for modifier keys


Is there a way to check for modifier keys in AppleScript Studio apps?


if( shift key is pressed )then
end if


Nope, as far as I know. You may need osaxen such as Jon’s Commands or HipTools.

That’s what I was afraid of. Thanks jj!

Actually, it depends on what you’re trying to do. What is your particular use? If you are trying to see if a key was down when you click a button you can use this, attached to the mouse down event of the button…

on mouse down theObject event theEvent
	if name of theObject is "button" then
		if command key down of theEvent then
			set keyDown to "Cmd"
		else if option key down of theEvent then
			set keyDown to "Opt"
		else if control key down of theEvent then
			set keyDown to "Ctrl"
		else if shift key down of theEvent then
			set keyDown to "Shft"
			set keyDown to ""
		end if
		set contents of text field "textField" of window "window" to keyDown
	end if
end mouse down

I’ve noticed that a few other objects support the mouse down or keyboard down events, both of which can use the key down checks shown above. Let us know what specifically you’re trying to do and what objects you’d like to use to handle the check. Some objects can be scripted to handle keys down (mouse down, keyboard down), natively support keys down (modifier keys), or there may be other workarounds besides external osax.


What about determining whether the Option key was held down or not?

I have an application that has 2 ways to do something, and I automatically choose what I think the best method is by doing some checks first. I’d like to still give the option to use the other method, but still only use a single button. So I was thinking I could have the Option button toggle the title of the single button from “Locate AdobeFnt.lst files” to “Find AdobeFnt.lst files” rather than having two big huge buttons (which doesn’t look all that great).

This is sort of a hybrid ASStudio ObjC app, since I’m using a toolbar, though from what I’ve heard, attempting this in ObjC would be pretty involved (subclassing NSWindow and watching for events).

Any idea if it’s possible just using AppleScript?

Thanks in advance…