Determine if option key down on launch of app

I’m developing an app that will perform an automatic function on launch unless the option key is held down. If so, the preferences window will appear, letting the user set the defaults for the automatic launching.

I can’t figure out how to catch the option key down event even though the docs say it is possible during application events. I am trying this in the on on Launched application event like this:

on launched theObject
	if option key down of event then
		load nib "Preferences"
		set preferencesWindow to window "preferences"
		loadPreferences(preferencesWindow)
		set visible of preferencesWindow to true
	else
	       runProcess(theDuration, theRepetition)
	end if
end launched

Of course, this gives an error.

Is it possible to do this?

Thanks.

Interface events are only reported to the application and window objects after launching has finished. The only way to get keys down on launch is to use a carbon call via some custom obj-c. Check out this thread for a solution I posted that does just what you’re after.

j

Thanks Jobu

But I get the same errors WoddenBrain got from your post. The error is in GetCurrentKeyModifiers(). The system does not understand this call. Should some other subclass or extension be loaded in order to process that function?

That thread has the code in it, so let’s continue over there.

http://bbs.applescript.net/viewtopic.php?id=19065