How do I automate keystrokes within a gam…
apple Verified ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I'm playing an online game (Mac edition) and want to trigger a series of keystrokes by pressing only one key. Basically, when I press key '1', this needs to to trigger '2', '3', '4' and '5' at 5 second intervals, and then loop 2-3-4-5 until '1' is pressed again.
Can this be done with AppleScript?
8 replies
Sign in or join Beachball Help to reply.
- 0
V.K. ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi there.
if you are still interested in this, I sort of figured out why it wasn't working for you. there seems to be a strange bug in Automator affecting the service you were making. some good folks on Applescript forum helped me troubleshoot it
http://discussions.apple.com/thread.jspa?threadID=2253709&start=0&tstart=0while the bug is unfixed and clearly won't be fixed for some time to come the following workaround should work. change your service "Twist" to the following
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run {input, parameters}set theApp to "Twister"
set x to (do shell script "ps -x | grep " & quoted form of theApp & " | wc -l")
if (x as integer) > 2 then
tell application theApp to quit
else
tell application theApp to launch
end ifend run</pre>
then everything should hopefully work as expected.
- 0
V.K. ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
maybe... you can make a script that presses 2,3,4,5 forever and save it as an application. then make another one that when launched launches the first one if the first one is not running and quits it if it is running. then bind a shortcut to it (but not "1" please!!). or something like that...
the following script will press 2,3,4,5 forever until quit.start automator and choose to make an application. add the following "run apple script action"
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run {input, parameters}tell application "System Events"
repeat
keystroke "2"
delay 5
keystroke "3"
delay 5
keystroke "4"
delay 5
keystroke "5"
delay 5
end repeat
end tell
end run</pre>save and call it say, "myapp" or something.
then start automator and make another application that does this
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run {input, parameters}tell application "System Events"
if exists process "myapp" then
tell application "myapp" to quit
else
tell application "myapp" to launch
end if
end tell
end run</pre>save that. you can bind a keyboard shortcut to it using a 3rd party app launcher like Butler, Quicksilver or launchbar. or you can use automator and save it as a service instead of an application and bind a keyboard shortcut to it in system preferences->keyboard->keyboard shortcuts->services. that does not require 3rd party software but may be a tad slower to launch than using an app launcher.
- 0
Luke Janicke ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
FA, I've tried that. However, I need to be able to start and stop the sequence while in the game. AppleScript/Automator can easily perform this with just a few lines of code. I just don't have the programming knowledge to write them.
- 0
V.K. ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Luke Janicke wrote:
It works. Kinda. I called the Application 'Twister' and used a Service which I called 'Twist' with shortcut ^1. I don't think pressing ^1 a second time is stopping the Application.does it start twister ok though? do you perhaps have something else tied to control+1?
- 0
Luke Janicke ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
It almost seems to work if I "Run" the first script from within Automator. It starts the second script. When I run the first script again, it stops the second Script. But if I do ANYTHING else (e.g. shortcut to Service, click Application in menu) it all gets messed up.
- 0
- 0
Luke Janicke ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
It works. Kinda. I called the Application 'Twister' and used a Service which I called 'Twist' with shortcut ^1. I don't think pressing ^1 a second time is stopping the Application.
- 0
felineaids ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Download mouse and keystroke recorder from mac section of CNET.
FA