Keystroke: Option Key Only

Is there a way to have Keyboard Maestro type a keystroke of Option. I don’t want Option-[another key], simply the Option key. I would even be content if I could have Keyboard Maestro type text and have it use the equivalent code of the Option key, which is 58.

I have tried using Keyboard Maestro to execute Applescript in two different ways:

tell application "System Events"
   key down option
   key up option
end tell

AND

tell application "System Events"
   key code 58 -- Option key
end tell

Though both these AppleScripts do what they say, they are ignored as a user interface key press. I need to find a way to have it look like I am pressing the Option key. I am not looking to make the option key a trigger.

Keyboard Maestro cannot press (or press and hold) just a modifier key.

In all likelihood, the target application is checking the system modifier flag state, which would not necessarily be set by simulating a modifier keypress anyway.

Sorry I don’t have a better answer for you.

Thanks Peter.

In that case I am going to try to skin the cat in a different way. I can make a change to a plist file to get the same result I want but I am learning more than I wish I had to about how Mavericks uses a cached version of plist files when it boots up. I am trying to figure out how to use what I believe needs to be done, CFPreferencesAppSynchronize, possibly with python, which I have never used before.

https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFPreferencesUtils/index.html#//apple_ref/c/func/CFPreferencesAppSynchronize

I use Keyboard Maestro execute to modify the com.apple.universalaccess.plist file to one of the two entries below.defaults write com.apple.universalaccess mouseDriver 0defaults write com.apple.universalaccess mouseDriver 1After writing the plist file it is not active because I believe it has to be synced with the cached version of prefs.

I am sure it is simple if you know what you are doing. I throw this out incase you or anyone else reading the post knows how to sync the plist with the cached version used by Mavericks.

. . . Stephen

@Stephen check this out:
Double Tap Control

The problem I always have with this is that when you try to execute with a key command the functions don’t work because you are holding down other modifiers to make this do what you want. You have to either put in a delay or have the AppleScript check if modifiers are held down.

I use StefanK’s checkModifierKeys http://www.klieme.ch/pub/checkModifierKeys.zip

then add this code at the start of my AppleScript

try

   set modifierkeysPressed to true

   repeat while modifierkeysPressed
      set modifierkeysPressed to (do shell script "/Library/Scripts/checkModifierKeys") is not "0"
      delay 0.2
   end repeat
   
on error
   display dialog "You do not have 'checkModifierKeys' installed. "
end try

tell application "System Events"
   key code 58 -- Option Key
   
   -- key down option
   -- key up option
end tell

The key down and key up have cause problems many times for me where it a modifier can get stuck on because up doesn’t register. Those are good of course if you need to insert a delay or functions in between.

I use the above AppleScript for Sibelius with the control modifier and then jump to menu shortcuts because the control key pressed and released will show a bunch of other alpha keys I can press to run other functions. That way I can use any key command in Keyboard Maestro and have it run the right functions after I let go of all modifiers.

I am sure you have long solved your issue but might be helpful to someone else. Ideally I would rather have Keyboard Maestro just press and release a modifier while I am still holding that modifier to execute another command.

In Keyboard Maestro 7.x there is now a Type Modifiers action that can press or press and hold (until the macro completes) a modifier.

It is likely that the interfaces you describe will ignore Keyboard Maestro holding the key down as well though.

1 Like

You can use the Pause Until action with the Modifiers condition at the start of your macro to pause the macro until you release the modifiers associated with the hot key trigger so that they do not interfere with the behaviour of the applications you are controlling.

3 Likes

Thanks for offering your solution. I haven't been able to keep the modifier pressed after being triggered by the hotkey with the instructions your provide. Could you pleas demonstrate what you meant by posting a screenshot of the editor? I might have misunderstood.

No key will ever be kept held down after the macro stops. So to keep a key held down, the macro must continue to run, perhaps with the Pause action at the end.