Join us on Discord!
You can help CodeWalrus stay online by donating here.

Tool-Assisted Speedrunning Mac Applications

Started by Yuki, October 30, 2016, 03:37:08 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yuki

Eh, I'm not sure anyone here have Macs but guess it'd be useful to put this here.

I've recently started playing with AppleScript, which is a pretty powerful thing that lets you script pretty much anything on your system, akin to bash shell scripts, except you can also script supported (and unsupported?) GUI applications to do things like clicking on a particular button or opening a particular menu. So of course, you can use it to TAS the whole system, why not?

Here's one script that I wrote for Undertale, there's a basis to TAS games, right now it pretty much starts the game and names the player as there's no real "key up/down" feature, or at least, it's broken... But at least it starts as soon as it's launched. To run this script you must have bought Undertale on Steam and have not saved yet.

Maybe it can be used to TAS calc games, that would be fun.

Code (AppleScript) Select

-- Keypress function, gets keycode, delay time (in 15ths of a second) and repeats in arguments
on kp(keycode, dtime, x)
tell application "System Events"
repeat x times
key code keycode
delay dtime / 15
end repeat
end tell
return
end kp

-- Useful key codes for Undertale
set z to 6
set x to 7
set c to 8
set kleft to 123
set kright to 124
set kdown to 125
set kup to 126

tell application "System Events"
-- Detects whether UI elements are enabled, if not we prompt the user to enable it in System Preferences then quit
set isEnabled to UI elements enabled
if isEnabled is false then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.security"
display dialog "This script uses macOS' GUI Scripting feature, which is currently disabled. Please enable Script Editor to control your computer in the security pane." with icon 1 buttons {"Cancel"} default button 1
return
end tell
end if
-- Opens Undertale from Steam (close Undertale first for optimum sync)
do shell script "open steam://run/391540"
-- Now we wait until the window is shown
repeat until window "UNDERTALE" of process "UNDERTALE" exists
end repeat
-- Make sure it's on top (kinda useless but we never know)
set frontmost of process "UNDERTALE" to true
end tell
-- Now press those keys super fast
kp(z, 45, 1)
kp(z, 1, 2)
kp(kright, 1, 2)
kp(kdown, 1, 1)
kp(z, 1, 1)
kp(kleft, 1, 3)
kp(kdown, 1, 5)
kp(z, 1, 1)
kp(kright, 1, 3)
kp(kup, 1, 2)
kp(z, 1, 1)
kp(kleft, 1, 3)
kp(kdown, 1, 2)
kp(z, 1, 1)
kp(kdown, 1, 1)
kp(kright, 1, 1)
kp(z, 1, 1)
kp(kright, 1, 1)
kp(z, 1, 1)


I do believe you can do that on other operating systems, Xorg in particular have a tool for simulating keypresses and mouse clicks, Windows probably have a program for that as well.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

Dream of Omnimaga

It amazes me that of all things, they left out two of the most important keys >.<

Interesting, though. I didn't know AppleScript could do that
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Yuki

As I tested, there is a key down/up function, but it only works with modifier keys. And the letter A, for some reason. Same for some command-line app I found. But yeah, otherwise, that's interesting.

I also tried it with a version of TilEm2 I compiled, but unfortunately, it doesn't even seem to detect the window.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

Yuki

I ported the whole thing in Python, it works quite nicely now. Also added a WIP of Undertale in there. It's not extremely stable, but it should work.

https://github.com/juju2143/tas
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

Powered by EzPortal