I recently wrote a program that intercepts a key and sends a CTRL-Z to the Surveyor window in TRS19. This short program can be edited for other versions of Trainz, as well as for intercepting and sending different keys. It does require that a programming system called "Autoit" be downloaded and installed into Windows. The system is free, and the language is similar to Visualbasic. The program below is for a left-handed user, since it uses the right control key. The only parameters you need are the key to look for, the key combination to send, and the name of the Surveyor window. The language is not threaded, so it includes some Sleep() statements, which may have to fine-tuned for your situations.
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$hDLL = DllOpen("user32.dll")
Global $actionitem
$title = "Close Undo Key?"
$wide = 200
$high = 50
$xpos =500
$ypos = 500
;build the window to terminate the script
GUICreate($title, $wide, $high, $xpos, $ypos)
GUISetStyle(BitOR($WS_POPUPWINDOW, $WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION), BitOR($WS_EX_CLIENTEDGE, $WS_EX_TOOLWINDOW))
$actionitem = GUICtrlCreateButton("YES", 25, 5, 55, 20)
GUISetState()
;Loop to check for terminate key and key press
While 1
;close script if window does not exist
;If NOT WinExists("Trainz Railroad Simulator 2019", "") Then
;ExitLoop
;EndIf
;Now check the GUI key
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $actionitem
_action()
ExitLoop
EndSelect
;Now check for the key pressed
If _IsPressed("A3", $hDLL) Then
;ConsoleWrite("Right Control Key was pressed" & @CRLF)
;MsgBox($MB_SYSTEMMODAL,"_IsPressed", "Right Control Key was pressed")
;MsgBox($MB_OK,"_IsPressed", "Exit Key?")
; snippet to send key to Trainz
;we no longer wait for the Trainz window,
;Local $hWnd = WinWait("Trainz Railroad Simulator 2019", "", 1)
;IF NOT $hWnd THEN MsgBox($MB_SYSTEMMODAL,"undo_works_1", "TRS19 not loaded")
;WinActivate($hWnd,"Trainz Railroad Simulator 2019")
;WinWait ($hWnd,"",1)
; Send a key to Trainz if the window is active
if WinActive("Trainz Railroad Simulator 2019","") Then
;ControlSend("Trainz Railroad Simulator 2019", "", "", "{F7}")
ControlSend("Trainz Railroad Simulator 2019", "", "", "^z")
EndIf
; Wait until key is released.
While _IsPressed("A3", $hDLL)
;Sleep(250)
Sleep(10)
WEnd
;ExitLoop
EndIf
;Sleep(250)
Sleep(10)
WEnd
DllClose($hDLL)
Func _Action()
;MsgBox($MB_OK,"_Action", "Exit Key?")
;we can't seem to close the script here, the calling code will slide out of the loop
GUIDelete()
EndFunc ;==>_Action
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$hDLL = DllOpen("user32.dll")
Global $actionitem
$title = "Close Undo Key?"
$wide = 200
$high = 50
$xpos =500
$ypos = 500
;build the window to terminate the script
GUICreate($title, $wide, $high, $xpos, $ypos)
GUISetStyle(BitOR($WS_POPUPWINDOW, $WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION), BitOR($WS_EX_CLIENTEDGE, $WS_EX_TOOLWINDOW))
$actionitem = GUICtrlCreateButton("YES", 25, 5, 55, 20)
GUISetState()
;Loop to check for terminate key and key press
While 1
;close script if window does not exist
;If NOT WinExists("Trainz Railroad Simulator 2019", "") Then
;ExitLoop
;EndIf
;Now check the GUI key
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $actionitem
_action()
ExitLoop
EndSelect
;Now check for the key pressed
If _IsPressed("A3", $hDLL) Then
;ConsoleWrite("Right Control Key was pressed" & @CRLF)
;MsgBox($MB_SYSTEMMODAL,"_IsPressed", "Right Control Key was pressed")
;MsgBox($MB_OK,"_IsPressed", "Exit Key?")
; snippet to send key to Trainz
;we no longer wait for the Trainz window,
;Local $hWnd = WinWait("Trainz Railroad Simulator 2019", "", 1)
;IF NOT $hWnd THEN MsgBox($MB_SYSTEMMODAL,"undo_works_1", "TRS19 not loaded")
;WinActivate($hWnd,"Trainz Railroad Simulator 2019")
;WinWait ($hWnd,"",1)
; Send a key to Trainz if the window is active
if WinActive("Trainz Railroad Simulator 2019","") Then
;ControlSend("Trainz Railroad Simulator 2019", "", "", "{F7}")
ControlSend("Trainz Railroad Simulator 2019", "", "", "^z")
EndIf
; Wait until key is released.
While _IsPressed("A3", $hDLL)
;Sleep(250)
Sleep(10)
WEnd
;ExitLoop
EndIf
;Sleep(250)
Sleep(10)
WEnd
DllClose($hDLL)
Func _Action()
;MsgBox($MB_OK,"_Action", "Exit Key?")
;we can't seem to close the script here, the calling code will slide out of the loop
GUIDelete()
EndFunc ;==>_Action