Re: Keystroke
Re: Keystroke
- Subject: Re: Keystroke
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 18 Apr 2008 06:18:23 -0400
- Thread-topic: Keystroke
on 2008-04-18 4:46 AM, Jay Louvion at email@hidden wrote:
> I¹m desperately trying to get a keystroke to work on a Quartz Composer
> animation, which is supposed to react every time someone (or something, i.e. a
> folder action script) triggers the mostly unused ³§² key.
>
> Unfortunately, to no avail, even though I have brough the focus to the
> application, nothing seems to work. Are there caveats when invoking keystrokes
> with Sys Events ?
I believe the 'keystroke' command is designed to insert a character into a
text view (i.e., to "type" the character), not to generate a key-down key-up
event sequence. Also, I believe the 'keystroke' command is designed to work
only with low-ASCII characters. You might have better luck with the 'key
code' command, but I doubt it, as discussed below.
1. If all you want is to "type" the "§" character into a text view that
currently has keyboard focus in a target application, your script can
contain something like this on a U.S. keyboard (using TextEdit as an
example):
activate application "TextEdit"
tell application "System Events"
key code 22 using {option down}
end tell
Note that it is NOT necessary in this case to turn on the "Enable access for
assistive devices" setting in the Universal Access pane of System
Preferences, nor to embed the 'key code' command in a 'tell process
"TextEdit"' block, as is normally required for GUI Scripting. Also, the
'activate' statement would not be necessary if the target application is
already frontmost.
I'm pretty much guessing at the following explanations for why other
techniques don't work: The reason 'keystroke "§"' generates a different
character (the German es-zett, or scharfes S) may be that the 'keystroke'
command is designed for use with low-ASCII characters only and ignores the
high bit of "§". The reason 'keystroke "6" using {option down}' generates
"6" may be that the application receiving the keystroke isn't written to
recognize Option-6 as a character (I only tested with TextEdit). In Leopard,
the following script fails with a 'Can't get keystroke "§"' error; I'm not
sure why it doesn't generate the German es-zett character as 'keystroke "§"'
does:
activate application "TextEdit"
keystroke character id 167
Writing it as ' keystroke (get character id 167)', or other variants of the
same technique, generates the same error.
2. However, I don't know that simply "typing" the "§" character using the
'key code' command will work, if what you want is to use this as a "hot key"
to trigger an event. I imagine it depends on whether the target application
is designed to recognize pressing Option-6 as a command instead of a
character, in the same way that using 'keystroke' or 'keycode' with a 'using
{command down}' clause acts as a keyboard shortcut only if the target
application is designed to recognize that keyboard shortcut.
I suspect that what you're trying to do simply can't be done using
AppleScript. Be sure to let us know if I'm wrong about that.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com
PreFab Software - www.prefabsoftware.com
_______________________________________________
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
References: | |
| >Keystroke (From: Jay Louvion <email@hidden>) |