* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Tool-Assisted Speedrunning Mac Applications  (Read 298 times)

0 Members and 1 Guest are viewing this topic.

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 2670
  • Post Rating Ratio: +17/-1
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • View Profile
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Tool-Assisted Speedrunning Mac Applications
« on: October 30, 2016, 03:37:08 am »
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.
« Last Edit: October 30, 2016, 03:52:27 am by Juju »


  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)

In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii:

YUKI-CHAAAANNNN

Online DJ Omnimaga

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Topic Management
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 17480
  • Post Rating Ratio: +83/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • View Profile
    • DJ Omnimaga music store
  • Gender: Male
Re: Tool-Assisted Speedrunning Mac Applications
« Reply #1 on: October 30, 2016, 04:34:03 pm »
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-73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)
??? ??? ??? ???

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 2670
  • Post Rating Ratio: +17/-1
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • View Profile
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Re: Tool-Assisted Speedrunning Mac Applications
« Reply #2 on: October 30, 2016, 04:49:00 pm »
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???)

In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii:

YUKI-CHAAAANNNN

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 2670
  • Post Rating Ratio: +17/-1
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • View Profile
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Re: Tool-Assisted Speedrunning Mac Applications
« Reply #3 on: November 13, 2016, 11:20:27 pm »
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???)

In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii:

YUKI-CHAAAANNNN

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games