Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Last active February 20, 2024 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save primaryobjects/d35ad1d3c288f7aeb6d075cd86c6e7f5 to your computer and use it in GitHub Desktop.
Save primaryobjects/d35ad1d3c288f7aeb6d075cd86c6e7f5 to your computer and use it in GitHub Desktop.
AutoIt utility for easier SendKey, commands. Automate Final Fantasy II 2 level-up, ff2

AutoIt SendKey Utility Script

An easy way to automate SendKey commands with AutoIt.

What is it?

A basic library script that allows sending repeated counts of SendKey() commands along with a delay inbetween them.

It's a great utility to use for automatig arcade video games to simulate key presses and allow easier leveling up or grinding. The example included is for Final Fantasy II to automate leveling up two players' ice magic spells.

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$count = 125
$label = 0
$button = 0
Func _WriteErrorLog($ErrorMessage)
FileWriteLine(@ScriptDir & "\" & @ScriptName & ".log", @HOUR & ":" & @MIN & ":" & @SEC & ": " & $ErrorMessage)
EndFunc ;==>WriteErrorLog
Func CheckGUI()
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE Or $msg = $button
Exit
EndSelect
EndFunc
Func Setup($title)
; Create a GUI with various controls.
$gui = GUICreate($title, 300, 200)
$label = GUICtrlCreateLabel("Performing action 1/" & $count, 10, 10, 300)
; Create a button control.
$button = GUICtrlCreateButton("Cancel", 85, 85, 130, 30)
; Display the GUI.
GUISetState(@SW_SHOW, $gui)
; Register the CheckGUI function to be called every 100 milliseconds.
AdlibRegister("CheckGUI", 100)
Opt("SendKeyDownDelay", 20)
EndFunc
Func UpdateStatus($text)
GUICtrlSetData($label, $text)
EndFunc
Func SendKey($key, $presses = 1, $delay = 200)
For $i = 1 to $presses
Send($key)
Sleep($delay)
Next
EndFunc
Func SelectSpell($col, $row, $delay = 200)
; select magic
SendKey("{DOWN}", 1, $delay)
SendKey("z", 1, $delay)
; move to magic column
SendKey("{RIGHT}", $col, $delay)
; move to magic row
SendKey("{DOWN}", $row, $delay)
; select spell
SendKey("z", 2, $delay)
EndFunc
Func Clear($delay = 200)
; next player
SendKey("s", 4, $delay)
EndFunc
Func Close()
; Unregister the CheckGUI function before exiting.
AdlibUnRegister("CheckGUI")
EndFunc
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "autility.au3"
Setup("Final Fantasy II - Level Up Trick")
; Wait for the window to become active. The classname "CalcFrame" or "ApplicationFrameWindow" (Win11) is monitored instead of the window title
If WinActivate("pSX v1.13") Then
For $i = 1 to $count
UpdateStatus("Performing action " & $i & "/" & $count)
SendKey("{DOWN}")
SendKey("z")
SendKey("{RIGHT}")
SendKey("z", 2)
; next player
SendKey("{DOWN}")
SendKey("z")
SendKey("{DOWN}", 2)
SendKey("z", 2)
SendKey("s", 4)
Next
EndIf
Close()
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "ff2-utility.au3"
Setup("Final Fantasy II - Level Up Trick")
; Wait for the window to become active. The classname "CalcFrame" or "ApplicationFrameWindow" (Win11) is monitored instead of the window title
If WinActivate("pSX v1.13") Then
For $i = 1 to $count
UpdateStatus("Performing action " & $i & "/" & $count)
SelectSpell(1, 0)
SelectSpell(0, 2)
SelectSpell(1, 6)
Clear()
Next
EndIf
Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment