No internet connection
  1. Home
  2. How to

How to simulate pressing return key with option key held down?

By @anon6770933309
    2018-07-03 11:50:23.650Z

    Basically I am looking for a JavaScript equivalent to this little AppleScript:

    property shortDelay : 0.1
    property medDelay : 0.3
    
    tell application "System Events"
    	try -- Important to use a try block because down keys can get stuck
    		key down {option}
    		delay shortDelay
    		keystroke return
    		delay medDelay
    		key up {option}
    	end try
    end tell
    

    The following does not work:

    sf.keyboard.modifiers({
        isOption: true
    });
    
    sf.wait({ intervalMs: 20 });
    
    sf.keyboard.press({
    	keys: 'return'
    });
    
    sf.wait({ intervalMs: 50 });
    
    sf.keyboard.modifiers();
    
    Solved in post #8, click to view
    • 7 replies
    1. Not tested, but you might be able to do:

      sf.keyboard.press({
      keys: 'alt+return'
      });

      1. ?@anon6770933309
          2018-07-03 11:53:42.701Z

          I tried

          sf.keyboard.press({
          keys: 'option+return'
          });

          which didn't work. I'll give yours a try.

          1. In reply tochrscheuer⬆:
            ?@anon6770933309
              2018-07-03 11:58:38.942Z

              Nope, doesn't work.
              I need it for this dialog.

              If you press "Remove" (= return) while holding down the option key it will clear the undo queue.

              1. Oh, that's a nice feature!
                Hm not with SF right now, but if you can find the "Remove" button... eg. something... dialog.getFirstWithTitle("Remove").mouseClickElement({ isOption: true });
                That might be a workaround for now

                1. ?@anon6770933309
                    2018-07-03 12:04:02.804Z

                    Thx for the hint, will give it a try. 😉

                    1. In reply tochrscheuer⬆:
                      ?@anon6770933309
                        2018-07-03 12:20:28.784Z

                        OK, I have

                        sf.ui.proTools.focusedWindow.getFirstWithTitle("Remove").mouseClickElement({ isOption: true });
                        

                        but this works only half way through, it doesn't press the option key it seems, little video attached.

                        demo.mov (648.4 kB)

                  • ?
                    @anon6770933309
                      2018-07-04 11:28:25.980Z

                      Got it:

                      // Click "Remove" button and clear undo queue
                      sf.keyboard.modifiers({ isOption: true });
                      sf.ui.proTools.focusedWindow.getFirstWithTitle("Remove").elementClick();
                      

                      😀

                      ReplySolution