Go Back   MacRumors Forums > Apple Systems and Services > Mac Basics and Help

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 11, 2012, 03:36 AM   #1
yeeehaw
macrumors newbie
 
Join Date: Jun 2012
Simple way to automatically press a few keys, and loop?

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.

Last edited by yeeehaw; Oct 11, 2012 at 03:42 AM.
yeeehaw is offline   0 Reply With Quote
Old Oct 11, 2012, 04:06 AM   #2
Stooby Mcdoobie
macrumors 6502a
 
Stooby Mcdoobie's Avatar
 
Join Date: Jun 2012
Location: Dallas, TX
You could probably use Automator to create a script for what you want to do.
Stooby Mcdoobie is offline   0 Reply With Quote
Old Oct 11, 2012, 04:12 AM   #3
barredfreak
macrumors 6502
 
Join Date: Jan 2012
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.
barredfreak is offline   0 Reply With Quote
Old Oct 11, 2012, 04:15 AM   #4
yeeehaw
Thread Starter
macrumors newbie
 
Join Date: Jun 2012
Quote:
Originally Posted by Stooby Mcdoobie View Post
You could probably use Automator to create a script for what you want to do.
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.
yeeehaw is offline   0 Reply With Quote
Old Oct 11, 2012, 08:58 AM   #5
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
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
Quote:
repeat (forever)
Repeats a statement (or statements) until an exit statement is encountered.

Important: A repeat (forever) statement will never complete unless you cause it to do so.
To terminate a repeat (forever) statement, you can:

Use an exit statement and design the logic so that it eventually encounters the exit statement.
Use a “return” statement, which exits the handler or script that contains the loop, and therefore the loop as well.
Use a try statement and rely on an error condition to exit the loop.
Info : https://developer.apple.com/library/...83-CH6g-127362
__________________
Space Corps Directive 34124

Last edited by kryten2; Oct 11, 2012 at 09:30 AM.
kryten2 is online now   2 Reply With Quote
Old Nov 22, 2012, 05:22 AM   #6
dumlovesyou
macrumors newbie
 
Join Date: Nov 2012
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!

Last edited by dumlovesyou; Nov 22, 2012 at 05:40 AM.
dumlovesyou is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Mac Basics and Help

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Making 2 keys (or key + rightclick) press at same time... keybinding, macro? Sean Dempsey OS X 0 Apr 16, 2014 09:58 PM
(HELP) How can i make a macro to press 2 keys at once? magmork Mac Programming 2 Mar 8, 2014 06:09 PM
Audio player with simple rewind / replay / loop? svenr Mac Applications and Mac App Store 6 Jan 27, 2013 05:05 PM
Harder to press certain keys on keyboard? macbookairowner Mac Basics and Help 1 Nov 25, 2012 12:28 AM
Simple Button Press Fix For Early Bought Cases for iPhone 5 albert1028 iPhone Accessories 0 Oct 12, 2012 02:13 AM

Forum Jump

All times are GMT -5. The time now is 06:39 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC