Re: Keystroke
Re: Keystroke
- Subject: Re: Keystroke
- From: KOENIG Yvan <email@hidden>
- Date: Fri, 18 Apr 2008 13:53:58 +0200
Le 18 avr. 2008 à 12:18, Bill Cheeseman a écrit :
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.
If I remember well, Jay is using a French keyboard.
With this keyboard, we don't press any modifier to get the § character.
Pressing the key [6] is sufficient.
We get the 6 pressing [6] + shift.
option + 6 gives ¶
option + shift + 6 gives å (LATIN SMALL LETTER A WITH RING ABOVE)
Given that, keystroke "§" send the character ß.
When I must enter the character § in a text, I found no other soluce
than:
-- [SCRIPT]
my enterIt("§")
on enterIt(c)
set the clipboard to c
set theApp to "Pages"
tell application theApp to activate
tell application "System Events" to tell (first process whose title
is theApp) to keystroke "v" using {command down}
end enterIt
-- [/SCRIPT]
But this doesn't help Jay.
Yvan KOENIG (from FRANCE vendredi 18 avril 2008 13:53:29)
_______________________________________________
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