A Solution for the UNDO button in Trainz

pitkin

Well-known member
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
 
Can't one just simply press Ctrl + Z ?

Yes they could. But the argument that left handed people are putting up is that because both the mouse and Ctrl-Z are on the same side of the keyboard, they have to leave the mouse to press Ctrl-Z. It would be a similar situation for a right handed person using the mouse and the numeric keypad.

It is very much a personal preference issue. I always use Ctrl-Z in all my programs, never a mouse equivalent (Undo and Redo buttons), but I am right handed. I also have no problems using the mouse and the numeric keypad either.

That is my understanding anyway.
 
You can also open the Control Settings scroll down to UNDO and add any key combo you like as the alternate. Here is an example of some right hand side of the keyboard combos.

2020-02-06_091539.png
 
Tony,

I just tried that on my TRS19 (not SP1) and it doesn't work. The window does not distinguish between the right and left control key. It thinks both are left control.
 
What about Shift? Or a single key rather than a combo?



I did not try to determine whether Trainz can distinguish between left and right shift keys. Probably not a good idea to use shift anyway, as someone might be typing a name and wanting to use the shift key. The control key without a concurrent key seemed a good choice, since by itself it doesn't seem to do anything in Trainz. In any event, there seems to be little interest in my submission, but it is there nonetheless if someone finds it useful. A major target of Autoit is for automating installations and other activities that involve Windows, keys, and folders. If one were to develop a library of functions, such as retrieving and installing Trainz auto-backups for example, there would be a lot fewer repeating questions on the forum. (Visual Basic could also do this, but Autoit is really aimed at this sort of thing).
 
Yea I meant using the Control Settings to bind a single key.

Here's one more thing to add to this discussion that was brought to my attention today. There are actually NO EXTRA clicks involved if you drag your mouse down and release.

i.e.
* Click Tools menu
* Hold LMB
* Drag down to Undo
* Release
* Review the operation (to make sure you spotted what was undone)
* Repeat

The only difference here is the time it takes to move the mouse (half a second?) and maybe a little bit more dexterity to move to Undo or Redo. After playing with it to undo a dozen trees I placed, it was pretty much a painless exercise. I'd be interested to hear if people knew that option existed and how they find it.
 
Another thing to consider. I'm a Mac guy and so used to the Mac aluminum keyboard that I use one on my Windows machine. (And reset the control and command keys as per Mac, to be consistent between machines.) The keyboard has no numeric pad so I purchased an "add on" usb keypad (mine is by Jelly Comb) which allows me to put it on the left side of the keyboard. I use it primarily for the arrow keys to help movements on the map why keeping right hand on mouse but can, of course, use it for any numeric keypad function. Very handy to have one on the left side. Of course, the normal PC user would also need obtain similar PC keyboard (no built in numeric keypad) in order to do same but keyboards are cheap.
 
It would be hell of a lot easier if you put the 'undo and redo button' back to where they were before. What exactly is the problem?
Macka
 
It would be hell of a lot easier if you put the 'undo and redo button' back to where they were before. What exactly is the problem?

Tony did make a post on that very point. If I can recall correctly (it is early morning here) he mentioned that they restored the buttons in a build alpha only to encounter more problems as a result - i.e. the buttons did not work correctly. Like John stated in another post - "pull a thread here and something unravels there".
 
I think my comment was "we're investigating the various options, it isn't a case of flicking a switch and they magically reappear". This includes options such as configurable menus, right-click on the option which would leave the menu open (so in effect, turning it into a button like it was before), a hack to add them to the top menu bar (possibly with a settings option to enable/disable)

I'm still interested in hearing feedback about the "one click" method using the new menu (see post #10). Has anyone actually tried it? It is certainly quicker than the two click option (which is what I expect most people to be using), and not quite as quick as the old one.

Also I'd appreciate feedback on the effectiveness of binding a single key (like the '.' and '/' keys) which you can mash with your spare hand to your heart's content.
 
Last edited:
Thanks Tony - that works too - I hadn't tried that trick before.
Will likely stick to my preferred shortcut key methods (i.e. the universal Windows keyboard combos Ctrl+Z and Ctrl+Y) out of sheer habit, but will occasionally resort to this new method just to prove that you can still teach an old dog new tricks. :)
 
I tried it just to confuse myself, which happens quite easily without trying too hard, and then went back to my tried and true CTRL+Z, CTRL+Y, which I've always used without issue.
 
Please can we have the other route building tools back on the bar, not just the undo/redo.
Quick Drive
Search Filter (for picklists)
Wireframe View

I've been using them for so many years now, it's become almost a reflex action to use them for route building.
I am doing my route building in TANE, I've stopped using TRS19 for now because I can't update it and use it efficiently and don't want to use an outdated version.

Luckily TANE SP4 has now become a really good reliable tool.
I hope that when I install the official Public Release that you have no more toolbar surprises for us.
 
I totally agree with Graham. It is a pain to find "undo" where it is now, and agree that the toolbar including Search Filter and Wireframe should go back where they were. We want the toolbar back!
 
Back
Top