Skip to content

Instantly share code, notes, and snippets.

@Jarvie8176
Last active August 17, 2020 15:11
Show Gist options
  • Save Jarvie8176/2416095064dde5df83f57bf40ae49c6a to your computer and use it in GitHub Desktop.
Save Jarvie8176/2416095064dde5df83f57bf40ae49c6a to your computer and use it in GitHub Desktop.
;**
;* configuration
;*
craft_count := 30 ; how many items to be crafted
practice_mode := false
macro_keys := [ [5, 8] ] ; [ [macro key, duration in seconds], ... ]
start_hotkey = F10 ; key to start the script
stop_hotkey = F12 ; key to cancel & reload the script
exit_hotkey = F11 ; key to force exit the script
craft_menu_key = N ; key to open craft menu
confirm_key = Numpad0
left_key = Numpad4
selection_wait_time := 200 ; milliseconds
pre_craft_wait_time := 1500 ; milliseconds
post_craft_wait_time := 2000 ; milliseconds
;**
;* setup
;*^
craft_done_count := 0
Hotkey, %start_hotkey%, Run
Hotkey, %stop_hotkey%, Stop
Hotkey, %exit_hotkey%, Exit
Pause, Off
return
Run: ; hotkey to start
craft_done_count = 0 ; counter reset
OpenCraftMenu()
Loop, %craft_count% {
DoCraft()
}
Msgbox craft script finished
return
Stop:
Msgbox craft script stopped
Reload
return
Exit:
Msgbox craft script exited
ExitApp
;**
;* implementation
;*
Log(text) {
OutputDebug % "AHK | " text
}
PressKey(key, wait_time) {
Log("key " key " wait_time " wait_time)
WinGet, pid, List, FINAL FANTASY XIV
ControlSend, , {%key%}, ahk_id %pid1%
Sleep, %wait_time%
}
OpenCraftMenu() {
global selection_wait_time
global craft_menu_key
global confirm_key
PressKey(craft_menu_key, selection_wait_time)
PressKey(confirm_key, selection_wait_time)
PressKey(confirm_key, selection_wait_time)
}
OpenCraftDialog() {
global selection_wait_time
global confirm_key
global left_key
global practice_mode
PressKey(confirm_key, selection_wait_time)
if (practice_mode) {
PressKey(left_key, selection_wait_time)
PressKey(left_key, selection_wait_time)
}
PressKey(confirm_key, selection_wait_time)
PressKey(confirm_key, selection_wait_time) ; in case of window focus lost
}
DoCraft() {
global pre_craft_wait_time
global post_craft_wait_time
global craft_count
global craft_done_count
OpenCraftDialog()
Sleep, %pre_craft_wait_time%
RunMacros()
craft_done_count++
message := "craft done (" craft_done_count "/" craft_count ")"
Log(message)
Sleep, %post_craft_wait_time%
}
RunMacros() {
global macro_keys
for index, item in macro_keys {
macro_key := item.1
duration := item.2 * 1000
PressKey(macro_key, duration)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment