.
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: A Solution for the UNDO button in Trainz

  1. #1
    Join Date
    Nov 2006
    Location
    United States of America, Colorado, Colorado Springs
    Posts
    667
     

    Default A Solution for the UNDO button in Trainz

    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
    I7-8700K
    1070Ti
    PCIe SSD operation (program and build)

  2. #2
    Join Date
    Aug 2019
    Location
    In Front Of My PC
    Posts
    680
     

    Default

    Can't one just simply press Ctrl + Z ?
    My apologies to all. I have decided that in these horrible current events, we all need to stick together as a Community

  3. #3
    Join Date
    Nov 2006
    Location
    Australia, NSW, Sydney
    Posts
    6,514
    Blog Entries
    3
     

    Default

    Quote Originally Posted by MP242 View Post
    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.
    TRS19 Platinum 105100 - TRS19 SP1 (standard) 105096 - TANE SP4 105766

  4. #4
    Join Date
    Nov 2006
    Location
    United States of America, Colorado, Colorado Springs
    Posts
    667
     

    Default

    Quote Originally Posted by MP242 View Post
    Can't one just simply press Ctrl + Z ?

    Yes, of course.
    I7-8700K
    1070Ti
    PCIe SSD operation (program and build)

  5. #5
    Join Date
    Nov 2006
    Location
    Australia, Qld
    Posts
    6,060
     

    Default

    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.

    Tony Hilliam

    Got questions about TRS19? Click here for TRS19 FAQs

    Looking for answers to in-game functionality? Click here for help

  6. #6
    Join Date
    Nov 2006
    Location
    United States of America, Colorado, Colorado Springs
    Posts
    667
     

    Default

    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.
    I7-8700K
    1070Ti
    PCIe SSD operation (program and build)

  7. #7
    Join Date
    Nov 2006
    Location
    Australia, Qld
    Posts
    6,060
     

    Default

    What about Shift? Or a single key rather than a combo?
    Tony Hilliam

    Got questions about TRS19? Click here for TRS19 FAQs

    Looking for answers to in-game functionality? Click here for help

  8. #8
    Join Date
    Nov 2006
    Location
    United States of America, Colorado, Colorado Springs
    Posts
    667
     

    Default

    Quote Originally Posted by Tony_Hilliam View Post
    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).
    I7-8700K
    1070Ti
    PCIe SSD operation (program and build)

  9. #9
    Join Date
    Nov 2006
    Location
    United States of America, Colorado, Colorado Springs
    Posts
    667
     

    Default

    Quote Originally Posted by Tony_Hilliam View Post
    What about Shift? Or a single key rather than a combo?


    Of course my program can send a single key. But what would be the point, why not just press that key to begin with?
    I7-8700K
    1070Ti
    PCIe SSD operation (program and build)

  10. #10
    Join Date
    Nov 2006
    Location
    Australia, Qld
    Posts
    6,060
     

    Default

    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.
    Tony Hilliam

    Got questions about TRS19? Click here for TRS19 FAQs

    Looking for answers to in-game functionality? Click here for help

  11. #11
    Join Date
    Oct 2018
    Location
    USA - North Carolina
    Posts
    1,015
     

    Default

    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.
    TRS19 SP1(Plus), 105100(plus), 106618(+beta)
    ASUS B450M-A/CSM, GTX 1060-6 Windforce


  12. #12
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    81
     

    Default

    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

  13. #13
    Join Date
    Sep 2011
    Location
    Denmark
    Posts
    501
     

    Default

    Quote Originally Posted by macka View Post
    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
    Hear, hear...

    Regards Claus
    "it's a visual thing. Terrain that looks ok at lower "post processing" settings looks like an acid trip on ultra".

  14. #14
    Join Date
    Nov 2006
    Location
    Australia, NSW, Sydney
    Posts
    6,514
    Blog Entries
    3
     

    Default

    Quote Originally Posted by macka View Post
    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".
    TRS19 Platinum 105100 - TRS19 SP1 (standard) 105096 - TANE SP4 105766

  15. #15
    Join Date
    Nov 2006
    Location
    Australia, Qld
    Posts
    6,060
     

    Default

    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 by Tony_Hilliam; February 6th, 2020 at 08:12 PM.
    Tony Hilliam

    Got questions about TRS19? Click here for TRS19 FAQs

    Looking for answers to in-game functionality? Click here for help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •