Simple way to automatically press a few keys, and loop?

Discussion in 'Mac Basics and Help' started by yeeehaw, Oct 11, 2012.

  1. yeeehaw, Oct 11, 2012
    Last edited: Oct 11, 2012

    macrumors newbie

    Joined:
    Jun 29, 2012
    #1
    I have a game where I want to press, "3, 2, 1, left click" and keep looping that. How would I go about doing that? Thanks.
     
  2. macrumors 6502a

    Stooby Mcdoobie

    Joined:
    Jun 26, 2012
    #2
    You could probably use Automator to create a script for what you want to do.
     
  3. macrumors 6502

    Joined:
    Jan 9, 2012
    #3
    By using a program called Automator.

    It comes pre-installed with your Mac, so check in your Launchpad/Applications folder. You can easily search the forums/Google for tutorials on how to use Automator to complete tasks which require a loop.
     
  4. thread starter macrumors newbie

    Joined:
    Jun 29, 2012
    #4
    Thanks, I tried that but I don't know how to write the apple scripts. I gave it my best attempt with this:
    tell application "Torchlight"
    repeat
    keystroke "3"
    keystroke "2"
    keystroke "1"
    end repeat
    end tell

    but it gave me an error and didn't work. Also, I don't know how to tell it to left click.
     
  5. kryten2, Oct 11, 2012
    Last edited: Oct 11, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #5
    Try this :

    Code:
    GUI()
    --do stuff with UI scripting
    -- Activate the application you'd like to target
    tell application "Torchlight" to activate
    tell application "System Events"
    	-- Send your keystroke
    	tell process "Torchlight"
    		repeat
    			keystroke "3"
    			keystroke "2"
    			keystroke "1"
    			click
    		end repeat
    	end tell
    end tell
    
    on GUI()
    	tell application "System Events"
    		if UI elements enabled then
    		else
    			repeat until UI elements enabled is true
    				beep
    				tell application "System Preferences"
    					activate
    					set current pane to pane "com.apple.preference.universalaccess"
    				end tell
    				tell application "Finder"
    					activate
    					display dialog "UI element scripting is not enabled. Please check \"Enable access for assistive devices\"  Then click \"ok\""
    				end tell
    			end repeat
    		end if
    	end tell
    end GUI
    Info : https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_control_statements.html#//apple_ref/doc/uid/TP40000983-CH6g-127362
     
  6. dumlovesyou, Nov 22, 2012
    Last edited: Nov 22, 2012

    macrumors newbie

    Joined:
    Nov 22, 2012
    #6
    Hello,

    So what can I do to make it loop every 0.1 seconds for just 7 minutes? And how exactly can I make it stop? Thank you!
     

Share This Page