Beware of key down!

I just tried a snippet of code with a very nasty outcome.

tell application “System Events”
key down comand
keystroke “v”
end tell
(I didn’t put this in the Applescript BBCode for obvious reasons.)

Aparently without the key up line, my system behaves as if the command key is held down, in every app! including the Dock!

I had to restart to restore sanity. I got the snippet from a compile script, and have since searched for the keywords and have not found them anywhere.

Model: Early 2011, 15", MacBook Pro
AppleScript: 2.5.1
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Hi,

to press modifier keys temporarily, write


tell application "System Events"
	keystroke "v" using command down
end tell

Yes, thanks, thats what I normally use.
I’m just surprised that I don’t see key down in the AS Language Guide, the System Events dictionary or a search on this site.

Hello.

I have this script, (chmod to u+x killsysevents), in my script folder for the hope of executing it when such things happens. Activity monitor is also open at all times, sometimes I manage there. (When control is down.)

I try those two things before I give up and log out. (Pressing shift and Q should have made you just log out, but I don’t know if the keyboard really gets reset by logging out.

#!/bin/bash
# Kills System Events nicely
ps -Al | grep System\ Events | head -n 1 | grep grep || killall System\ Events

Edit

The solution to this problem is of course to make an automator service, that makes key command up, key option up, key control up, key shift up.

You then create a short-cut key like ctrl-shft-command-up K for it. That way you should always be able to “unlock” the keyboard.

Maybe the key down is described in the venerable Scripting Additions Guide.

I don’t remember seeing key down in an Apple resource.
Maybe it was available in an old OSAX.

Yvan KOENIG (VALLAURIS, France) dimanche 24 mars 2013 21:45:04