Skip to content

Instantly share code, notes, and snippets.

@johnholbrook
Last active January 4, 2021 01:40
Show Gist options
  • Save johnholbrook/92d387364f85fa848266a987ab23ab84 to your computer and use it in GitHub Desktop.
Save johnholbrook/92d387364f85fa848266a987ab23ab84 to your computer and use it in GitHub Desktop.
AutoHotkey script for automating various aspects of VEX Tournament Manager
; ----------------------------------------------------------------------------------------------------------------------
; File .........: tm.ahk
; Description ..: AutoHotkey script for automating various aspects of VEX Tournament Manager
; Authors ......: John Holbrook (johnholbrook.us) and Philip Taylor (philipt.net)
; Changelog ....: 31 Dec. 2020 - Initial release
; ..............: 03 Jan. 2021 - Scaled all window coordinate clicks by screen DPI (function correct_for_dpi)
; NOTES ........: 1 - Due to unknown incompatabilities in the ExtListView library, this script must be run
; ..............: under a 32-bit version on AutoHotkey.
; ..............: 2 - Some parts of this script can be a little janky if you have multiple displays and they're not all
; ..............: at the same UI scaling level. In that case, make sure the TM window is on your primary display,
; ..............: or another display with the SAME UI scaling level as the primary display.
; ----------------------------------------------------------------------------------------------------------------------
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; SetControlDelay, 2000
; this is the "ExtListView" library by cryuz, as modified by this scirpt's authors
; Available here: https://gist.github.com/johnholbrook/7de188cf242c1b6600e17bdb86d9de30
#include <ExtListView>
; this is the title of the main TM window
tm_wintitle := "VEX Tournament Manager"
; this is the name of the field set whose timer you want to control
; (in other words, the title of the window with the timer controls in it)
field_set_name := "Match Field Set #1"
get_score_hwnd(){
tm := WinExist("VEX Tournament Manager")
hwnd := tm
loop
{
old_hwnd := hwnd
hwnd := DllCall("RealChildWindowFromPoint", "Ptr", hwnd, "Int64", (200<<32)|200, "Ptr")
}
until hwnd == old_hwnd
return hwnd
}
correct_for_dpi(x, y){
scale := A_ScreenDPI/96
tmp := "X" . Floor(x*scale) . " Y" . Floor(y*scale)
; MsgBox, %tmp%
return tmp
}
;start/pause match
F13::ControlClick, Button13, %field_set_name%
;end match early
F14::ControlClick, Button14, %field_set_name%
;queue driving skills
F15::ControlClick, Queue Driving Skills, VEX Tournament Manager
;queue programming skills
F16::ControlClick, Queue Programming Skills, VEX Tournament Manager
; send latest skills match to results screen
F24::
F17::
; Select "Skills Challenges" tab
LocX300Y60 := correct_for_dpi(300, 60)
ControlClick, %LocX300Y60%, VEX Tournament Manager
; Select "Driving Skills" Tab
LocX40Y80 := correct_for_dpi(40, 80)
ControlClick, %LocX40Y80% , VEX Tournament Manager
; get last driving skills match
driver_list_view := ExtListView_InitializeFromHwnd(get_score_hwnd())
driver_table_contents := ExtListView_GetAllItems(driver_list_view)
largest_driver_index := 0
largest_driver_value := 0
for index, value in driver_table_contents{
if (value[1] > largest_driver_value){
largest_driver_index := index
largest_driver_value := value[1]
}
}
; Select "Programming Skills" Tab
LocX125Y85 := correct_for_dpi(125,85)
ControlClick, %LocX125Y85%, VEX Tournament Manager
;get last programming skills match
prog_list_view := ExtListView_InitializeFromHwnd(get_score_hwnd())
prog_table_contents := ExtListView_GetAllItems(prog_list_view)
largest_prog_index := 0
largest_prog_value := 0
for index, value in prog_table_contents{
if (value[1] > largest_prog_value){
largest_prog_index := index
largest_prog_value := value[1]
}
}
; get location of list view
ControlGetPos, ctlx, ctly,,,, % "ahk_id" get_score_hwnd()
if (largest_prog_value > largest_driver_value){ ; last run was programming
; make sure row is visible
ExtListView_EnsureVisible(prog_list_view, largest_prog_index-1)
; get location of row
target := ExtListView_GetItemRect(prog_list_view, largest_prog_index-1)
}
else{ ; last run was driving
; switch to driving skills tab
ControlClick, %LocX40Y80%, VEX Tournament Manager
; make sure row is visible
ExtListView_EnsureVisible(driver_list_view, largest_driver_index-1)
; get location of row
target := ExtListView_GetItemRect(driver_list_view, largest_driver_index-1)
}
; Save current mouse coordinates to move the cursor back there later
MouseGetPos, mouse_pos_x, mouse_pos_y
; Right click latest skills match and send to results screen
WinActivate, VEX Tournament Manager
MouseClick, RIGHT, ctlx + target[1]*A_ScreenDPI/96 + 5, ctly + target[2]*A_ScreenDPI/96 + 5, 1, 0
Sleep, 50
Send, {Up}{Enter}
; move mouse back to previous position
MouseMove, mouse_pos_x, mouse_pos_y
; deinitialize ExtListView objects
ExtListView_DeInitialize(driver_list_view)
ExtListView_DeInitialize(prog_list_view)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment