Pressing the control key under script control
Pressing the control key under script control
- Subject: Pressing the control key under script control
- From: Michael Ziober <email@hidden>
- Date: Sun, 28 Mar 2004 22:20:57 -0800
Ron,
Your followup provided the breakthrough I needed, but it still wasn't
ASCIIseek. As you know, I thought that you mistyped your example, but
once I bothered to try it, I discovered that it compiled! So I took a
chance and tried "key up", and that parsed too! Using "ASCII character
246" got me nowhere, as did a bare "246", so I took a stab in the dark
and tried "control" The rest, as they say, is history.
Where did you discover "key down"? It's not in the dictionary for
System Events, which is why I assumed it wouldn't work. I should know
better than to trust the documentation over the code; code always wins.
Thank you for all your help.
Michael
tell application "KeyboardViewerServer" to activate
tell application "System Events"
try --don't even consider not using a try block!
key down control
delay 1
key down shift
delay 1
key down option
delay 1
key down command
delay 1
key up control
delay 1
key up shift
delay 1
key up option
delay 1
key up command
delay 1
key down {control, shift, option, command}
delay 1
key up {control, shift, option, command}
on error --logging out is the only other way to clear these
key up {control, shift, option, command}
end try
end tell
On Mar 28, 2004, at 9:16 PM, roncross wrote:
>
Hi Michael, I think that there is some confusion here that I would
>
like to clear up where I may be partly to blame. First, I am not
>
suggesting that you type the caret character (shift + 6). The ascii
>
code for the caret symbol is 94. If you use ASCIIseek and type shift
>
+ 6, you will see ascii code 94 that is related to the caret symbol
>
itself and will not do what you are asking. There is a control symbol
>
ascii 246 (on my computer, I get this by pressing alt + i) that looks
>
like a caret symbol, but it is actually the control symbol. I
>
apologize for the confusion. You may have to press the alt button
>
plus one of the alphabetical keys until you get to ascii 246 that is
>
the control symbol. Since ASCII codes are universal and standard, if
>
you try putting ascii 246 in your your script, it might work.
>
>
Second, I did mean keydown and not keystroke. I believe that your
>
version of system event has this command. I also have version 1.2.1
>
system events and the key down command works just fine.
>
>
thx
>
RLC
>
>
On Mar 27, 2004, at 12:24 PM, Michael Ziober wrote:
>
>
> Steven and Ron: Thanks for the leads. Unfortunately, they didn't pay
>
> off.
>
>
>
> On Fri, 26 Mar 2004 21:20:34 -0700, roncross wrote:
>
>> You can use ASCIIseek to simulate a control key command. On my
>
>> keyboard, it is ASCII number 246; it may be something different on
>
>> your
>
>> computer. Just put this in an applescript as follows:
>
>>
>
>> key down (ASCII character 246) -- on my machine the control key is
>
>> ASCII character 246. The control key will be a caret symbol.
>
>>
>
>> Be sure to wrap it with the appropriate tell commands, system events,
>
>> etc.... This is a system events.
>
>
>
> I'm not trying to TYPE the caret character here; I'm trying to PRESS
>
> the control key. Pressing only the control key in ASCIIseek displays
>
> nothing because it has no character code. I assume you meant
>
> "keystroke" above and not "key down", which I don't have in my
>
> version of System Events (1.2.1). Do you have something else
>
> installed which provides "key down"?
>
>
>
> On Fri, 26 Mar 2004 19:33:35 -0700, Steven Sanders wrote:
>
>> You might try Extra Suites at:
>
>> http://www.kanzu.com
>
>> It has the ability to type keys with modifier keys.
>
>
>
> Extra Suites has almost exactly the opposite of what I need: it
>
> allows TESTING to see if a modifier key is down, but no way to SET
>
> the state of a modifier key, which I now believe would be way beyond
>
> the abilities of a faceless app. I do not need a way to, for example,
>
> simulate the user typing Command-Z. I can already do that with System
>
> Events:
>
>
>
> tell application "System Events"
>
> keystroke "z" using {command down}
>
> end tell
>
>
>
> What I'm looking for is something more like this (which is not real
>
> code, only wishful thinking):
>
>
>
> tell application "System Events"
>
> keyboard press {control key} --press and hold the control key...
>
> tell process "iDVD"
>
> --iDVD now thinks the control key is being held down
>
> do amazing things
>
> end tell
>
> keyboard release {control key} --release the control key
>
> end tell
>
>
>
> I foresee two obstacles to my wish being fulfilled: This may be
>
> something that has to go all the way down to SystemUIServer or even
>
> the keyboard driver, which probably excludes anyone other than Apple
>
> from being able to do it; I can imagine poor error trapping leaving
>
> the keyboard with modifiers pressed, which would result in a really
>
> bad user experience. Even so, I still think it's worth suggesting...
>
>
>
> System Events
>
> Processes Suite
>
> Commands
>
> keyboard press option key/control key/shift key/command key
>
> keyboard release option key/control key/shift key/command key
>
>
>
> Any other ideas out there?
>
>
>
> Michael
>
>
>
> On Wednesday, March 24, 2004, at 10:32 AM, I wrote:
>
>
>
>> Does anyone know how to make iDVD 3 running on OS X 10.3.2 think that
>
>> _just_ the control key is down? Hopefully something better than "lay
>
>> a
>
>> book on the control key"! :-)
>
>>
>
>> iDVD (aside from its odd object model and dictionary) has an
>
>> unofficial feature which checks the state of the control key, plus a
>
>> few other things, when burning a disc, which allows it to be used to
>
>> automatically batch build and "burn" DVDs as disk images.
>
>> Unfortunately, iDVD is testing the key directly as opposed to whether
>
>> it is used as a modifier for a keyboard event, so "keystroke using
>
>> control down" isn't what I need.
>
>>
>
>> I have a keyboard map which indicates that the code for the control
>
>> key is 0x3B, but "key code 59" doesn't seem to have any effect. It
>
>> appears to generate a single keyboard event, rather than allowing me
>
>> to set the key state to down, send a command to iDVD, and then set
>
>> the
>
>> state to up. This makes sense because the syntax makes no distinction
>
>> as to the key state.
>
>>
>
>> Finally, I stumbled across this key combo by random experimentation:
>
>> press and hold LEFT control key, press and hold RIGHT control key,
>
>> release LEFT control key, release RIGHT control key. This locks the
>
>> control key in the down state. Press and release the LEFT control key
>
>> to unlock it. Oddly, this combination works only for the control key
>
>> and no other modifiers. It also seems to be independent of any
>
>> keyboard or universal access settings, so why is it there?
>
>>
>
>> While the last method is functional, it's also an ugly hack which is
>
>> very confusing when you forget that it's active! So, does anyone have
>
>> any wisdom on using key code or perhaps an OSAX that works with
>
>> Panther? I'm willing to entertain anything: BSD, SystemUIServer,
>
>> System Events, etc.
>
>>
>
>> Thanks,
>
>> Michael
>
>
>
>
>
thanks
>
Ronald Cross
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.