
For the gear switching (and any other keys that need to be held down, like the horn) you will want to program them using the following steps:
1. Make sure ‘Keystrokes’ is selected at the top of the programming pane for this key
2. Left-click your mouse in the top ‘On Press’ section to make sure it has the focus
3. Press the key(s) on your keyboard (like Shift+e) and hold them down
4. With your free hand, move the mouse cursor down to the ‘On Release’ area and left-click
5. Release both of the keys on your keyboard
6. Click Save and then repeat this step for other keys if needed
Programming in this way makes it so that holding the button/toggle will continue to send the command until it’s released and goes back to its standard position. We found this worked a bit better for the gears than a quick press.
Machinist wrote:Thanks George,![]()
This happens since RW2 cause RSC didn't informed P.I.Engineering about the cammand codes. I'm warning Keith (RailDriver support) about this message, in order to P.I.Engineering update the patch for MacroWorks3 (hopefully it is still working with TS 2012).
BTW, which is the script file name that I have to backup before change?![]()
Thanks,
Lisboa.
 
 lever(6).position(0).min = minvals(19) 'rotary 2 position 1 (off)
        lever(6).position(0).max = maxvals(19) 'rotary 2 position 1 (off)
   lever(6).position(0).upperthreshold=4 'must not be 0 w/o changing the logic below
   lever(6).position(0).lowerthreshold=4 'must not be 0 w/o changing the logic below
   lever(6).position(1).min = minvals(20) 'rotary 2 position 2 (slow)
        lever(6).position(1).max = maxvals(20) 'rotary 2 position 2 (slow)
   lever(6).position(1).upperthreshold=4 'must not be 0 w/o changing the logic below
   lever(6).position(1).lowerthreshold=4 'must not be 0 w/o changing the logic below
   lever(6).position(2).min = minvals(21) 'rotary 2 position 1 (full)
        lever(6).position(2).max = maxvals(21) 'rotary 2 position 1 (full)
   lever(6).position(2).upperthreshold=4 'must not be 0 w/o changing the logic below
   lever(6).position(2).lowerthreshold=4  'must not be 0 w/o changing the logic belowlever(6).position(0).min = minvals(19) 'rotary 2 position 1 (off)
        lever(6).position(0).max = maxvals(19) 'rotary 2 position 1 (off)
   lever(6).position(0).upperthreshold=0 'Default value=4, must not be 0 w/o changing the logic below
   lever(6).position(0).lowerthreshold=0 'Default value=4, must not be 0 w/o changing the logic below
   lever(6).position(1).min = minvals(20) 'rotary 2 position 2 (slow)
        lever(6).position(1).max = maxvals(20) 'rotary 2 position 2 (slow)
   lever(6).position(1).upperthreshold=0 'Default value=4, must not be 0 w/o changing the logic below
   lever(6).position(1).lowerthreshold=0 'Default value=4, must not be 0 w/o changing the logic below
   lever(6).position(2).min = minvals(21) 'rotary 2 position 1 (full)
        lever(6).position(2).max = maxvals(21) 'rotary 2 position 1 (full)
   lever(6).position(2).upperthreshold=0 'Default value=4, must not be 0 w/o changing the logic below
   lever(6).position(2).lowerthreshold=0 'Default value=4, must not be 0 w/o changing the logic below      Case 2007 '3 Position Rotary Switch 2
         Dim LightSWPosSensitivity as Integer 'Used to create a buffer around the Off and Full positions
         Dim LightSWDimSensitivity as Integer 'Used to create a buffer around the Dim position
         Dim HoldKeyTime as Integer 'Used to determine how long a key press is held down
         Dim HoldKeyDoubleTime as Integer 'Used for double-length keypresses
         Dim CurLightSWPos as Integer 'Values are 0=Off 1=Dim 2=Full 3=Not In Range
         Dim LightSwitchPosChanged as Boolean 'Used to verify switch is in a different position
         Dim LtSwLastAnalog as Integer 'Used to check if switch is still moving
         Dim LtSwLEDVal as Integer=0
         Dim LtOffLo as Integer
         Dim LtOffHi as Integer
         Dim LtDimLo as Integer
         Dim LtDimHi as Integer
         Dim LtFullLo as Integer
         Dim LtFullHi as Integer
         Dim LtSwFirstRun as Boolean
         Dim LtSwWriteToLED as Boolean
         Dim LtSwSkipThrottleStyleCheck as Boolean = False
         'Locomotive features variables used for creating exceptions to timing rules
         Dim LtSwCombinedThrottle as Boolean = False
         Dim LtSwGearLever as Boolean = False
         Dim LtSwTrainBrake as Boolean = False
         Dim LtSwLocoBrake as Boolean = False
         Dim LtSwDynamicBrake as Boolean = False
         'Debugging variables
         Dim LightSwitchDebug as Boolean   
         Dim LightSwitchReportedValue as String      
         Dim LtOffLoDebug as String
         Dim LtOffHiDebug as String
         Dim LtDimLoDebug as String
         Dim LtDimHiDebug as String
         Dim LtFullLoDebug as String
         Dim LtFullHiDebug as String
         
         LightSwitchDebug=False 'Should be set to False or message boxes will appear every time the switch changes positions
         'Tweakable values to modify sensitivity of each position and length of time keys are held down
         LightSWPosSensitivity = 5 'the higher the number, the broader the acceptable range for off and full positions
         LightSWDimSensitivity = 20 'Same as above but only for the dim position to account for drifting values coming from the center point of the switch
         HoldKeyTime = 250 'Base value for holding keys for this amount of time in milliseconds and gets adjusted later in the script based on ThrottleStyle
         'Do not change anything below this line as it will break the script
         LightSwitchPosChanged = False
         
         'Check for switch movement         
         If (AnalogValue(0)<>lever(6).LastValue) Then   'Switch movement detected
            'Determine Locomotive Features
            If (RailSimCombinedThrottleBrakeMin<>0 Or RailSimCombinedThrottleBrakeMax<>0) Then 'Combined Throttle
               LtSwCombinedThrottle=True
               'MsgBox("Combined Throttle Exists",1)
            Else
               LtSwCombinedThrottle=False
            End If
            If (RailSimGearLeverMin<>0 Or RailSimGearLeverMax<>0) Then 'Gear lever
               LtSwGearLever=True
               'MsgBox("Gear Lever Exists.",1)
            Else
               LtSwGearLever=False
            End If
            If (RailSimTrainBrakeMin<>0 Or RailSimTrainBrakeMax<>0) Then 'Train Brake
               LtSwTrainBrake=True
               'MsgBox ("Train Brake Exists.",1)
            Else
               LtSwTrainBrake=False
            End If
            If (RailSimLocoBrakeMin<>0 Or RailSimLocoBrakeMax<>0) Then 'Locomotive Brake
               LtSwLocoBrake=True
               'MsgBox ("Locomotive Brake Exists.",1)
            Else
               LtSwLocoBrake=False
            End If
            If (RailSimDynamicBrakeMin<>0 Or RailSimDynamicBrakeMax<>0) Then 'Dynamic Brake
               LtSwDynamicBrake=True
               'MsgBox ("Dynamic Brake Exists.",1)
            Else
               LtSwDynamicBrake=False
            End If
            LtSwLastAnalog=lever(6).LastValue
            LightSwitchReportedValue=AnalogValue(0) 'Convert the analog value to a string for debugging message boxes
            'Create ranges for switch positions
            LtOffLo = (lever(6).position(0).min-lever(6).position(0).lowerthreshold - LightSWPosSensitivity)
            LtOffHi = (lever(6).position(0).max-lever(6).position(0).upperthreshold + LightSWPosSensitivity)
            LtDimLo = (lever(6).position(1).min-lever(6).position(1).lowerthreshold - LightSWDimSensitivity) 
            LtDimHi = (lever(6).position(1).max-lever(6).position(1).upperthreshold + LightSWDimSensitivity) 
            LtFullLo = (lever(6).position(2).min-lever(6).position(2).lowerthreshold - LightSWPosSensitivity)
            LtFullHi = (lever(6).position(2).max-lever(6).position(2).upperthreshold + LightSWPosSensitivity)
            LtOffLoDebug = LtOffLo
            LtOffHiDebug = LtOffHi
            LtDimLoDebug = LtDimLo
            LtDimHiDebug = LtDimHi
            LtFullLoDebug = LtFullLo
            LtFullHiDebug = LtFullHi
            'Check if this is the first movement of the switch
            If (lastrp2=-1) Then
               LtSwFirstRun=True 'First run
            Else
            End If
            'Check current light switch position
            If (AnalogValue(0)<LtOffHi) Then 'Switch is in the Off position
               CurLightSWPos=0
            Else If (AnalogValue(0)>LtDimLo) And (AnalogValue(0)<LtDimHi) Then 'Switch is in the Dim position
               CurLightSWPos=1
            Else If (AnalogValue(0)>LtFullLo) Then 'Switch is in the Full position
               CurLightSWPos=2
            Else 'Switch is in between positions
               CurLightSWPos=3
            End If
            If (LtSwFirstRun=True) Then
               lastrp2=CurLightSWPos 'Since this is the first run we need to set the position the switch is in at the start
            Else
            End If         
            'Make sure current switch position is different than the last position
            If (CurLightSWPos<lastrp2) Or (CurLightSWPos>lastrp2) Then 'The switch is in a different range so run the code
               LightSwitchPosChanged=True 'The switch is in a valid range so continue running code
            Else
               LightSwitchPosChanged=False 'The switch is in the same range as the last position
            End If   
            
            If (CurLightSWPos<>3) Then 'Switch is in a valid position
               lastrp2=CurLightSWPos   
            Else
            End if
            If (LightSwitchPosChanged=True) Then 'The switch is in a different position so run the code below
               'Create special case exceptions to the rules below based on locomotive features.
               'Rule exception for BR294. This works because it is the only locomotive with a combined throttle with train and locomotive brakes
               If (LtSwCombinedThrottle=True And LtSwTrainBrake=True And LtSwLocoBrake=True And LtSwDynamicBrake=False And LtSwGearLever=False) Then
                  HoldKeyTime=HoldKeyTime-100
                  LtSwSkipThrottleStyleCheck=True
                  'MsgBox("BR294 Detected.",1)
               End If
               If (LtSwSkipThrottleStyleCheck=False) Then 'no exceptions have been applied so use default ThrottleStyle timing configuration
                  'Check ThrottleStyle to modify hold key times
                  Select Case (ThrottleStyle)
                     Case 0 'throttle as labeled on RD (throttle on bottom half)
                        'MsgBox("Throttle as labeled on RD",1)
                        HoldKeyTime=HoldKeyTime-50
                     Case 1 'throttle/train brake
                        'MsgBox("Throttle-Train Brake",1)
                        HoldKeyTime=HoldKeyTime
                     Case 2 'throttle/dynamic brake
                        'MsgBox("Throttle-Dynamic Brake",1)
                        HoldKeyTime=HoldKeyTime-100
                     Case 3 'all throttle
                        'MsgBox("All Throttle",1)
                        HoldKeyTime=HoldKeyTime-50
                  End Select
               End If 
               HoldKeyDoubleTime = (HoldKeyTime + HoldKeyTime + 200) 'This is used to calculate how long to hold down the key to simulate an extended keypress
         
               Select Case (CurLightSWPos)
                  Case (0) 'Set lights to Off                  
                     'SetRailSimValue(eRailSimControlID.HEADLIGHTS_ID, 1) 'toggle off headlights
                     'The following ScanCodes tell RD to send SHIFT+H to RW long enough to ensure lights turn off
                     MW3.sendScanCode("42:1,35:1") 'Press SHIFT (42) H (35)
                     MW3.insertDelay(HoldKeyDoubleTime) 'Uses double HoldKeyTime for extended keypress
                     MW3.sendScanCode("35:0,42:0") 'Release SHIFT (42) H (35)
                     LtSwLEDVal=63 'LED Value for 0
                     LtSwWriteToLED=True 'Finished this code block so it is ok to write to the LED
                     If (LightSwitchDebug=True) Then 'Switch debugging messages are turned on so display them
                        MsgBox("The current light switch position is: OFF. Current switch value is: " & LightSwitchReportedValue & ". Valid numbers for the range are: " & LtOffLoDebug & " - " & LtOffHiDebug & ".",1)
                     Else
                     End If
                  Case (1) 'Set lights to position 1                     
                     MW3.sendScanCode("42:1,35:1") 'Press SHIFT (42) H (35) 'Hold down SHIFT+H long enough to turn off lights
                     MW3.insertDelay(HoldKeyDoubleTime ) 'HoldKeyTime is doubled for extended keypress
                     MW3.sendScanCode("35:0,42:0") 'Release SHIFT (42) H (35)
                     MW3.insertDelay(50) 'Small delay before sending new keystrokes
                     MW3.sendScanCode("35:1") 'Press lower-case h (35)
                     MW3.insertDelay(HoldKeyTime)
                     MW3.sendScanCode("35:0") 'Release lower-case h (35)
                     LtSwLEDVal=6 'LED Value for 1
                     LtSwWriteToLED=True 'Finished this code block so it is ok to write to the LED
                     If (LightSwitchDebug=True) Then 'Switch debugging messages are turned on so display them
                        MsgBox("The current light switch position is: DIM (Front). Current switch value is: " & LightSwitchReportedValue & ". Valid numbers for the range are: " & LtDimLoDebug & " - " & LtDimHiDebug & ".",1)
                     Else
                     End If
                  Case (2) 'Set lights to position 2
                     'SetRailSimValue(eRailSimControlID.HEADLIGHTS_ID, 1) 'toggle on headlights
                     MW3.sendScanCode("35:1") 'Press lower-case h (35)
                     MW3.insertDelay(HoldKeyDoubleTime) 'Double the HoldKeyTime for extended keypress
                     MW3.sendScanCode("35:0") 'Release lower-case h (35)
                     LtSwLEDVal=91 'LED Value for 2
                     LtSwWriteToLED=True 'Finished this code block so it is ok to write to the LED
                     If (LightSwitchDebug=True) Then 'Switch debugging messages are turned on so display them
                        MsgBox("The current light switch position is: FULL (Rear). Current switch value is: " & LightSwitchReportedValue & ". Valid numbers for the range are: " & LtFullLoDebug & " - " & LtFullHiDebug & ".",1)
                     Else
                     End If
                  Case (3) 'Light switch is in an area between positions so do nothing
               End Select
               'write switch position to LEDs
               If (LtSwWriteToLED=True) Then 'OK to write to LEDs
                  Dim OutputReport() as Byte = {0,134,LtSwLEDVal,64,56,0,0,0,0}
                  Dim LtSwLEDDisplayCounter as Integer=0
                  Dim LtSwLEDWriteSpeedCounter as Integer=0
                  For LtSwLEDDisplayCounter=1 to 200
                     MW3.SendGenericOutput(MyDevice,OutputReport)
                  Next 
                  'Finished writing L code so get current speed to display
                  Dim speed As Single = GetRailSimValue(30, 0) 'speedometer
                  'make absolute and put in desired units
                  speed=Math.Abs(speed)
                  If (speedunit=True) Then speed=Math.Abs(speed*1.609344)         
                     Dim speeds As String=speed.ToString("000") 'assumes that the train will never be faster than 999, this rounds also
                     If (appactive=true) Then 'write current speed if RailWorks is still the active app
                        'write to LEDs
                        Dim AltOutputReport() as Byte = {0,134,ToDigits(speeds.Substring(2, 1)),ToDigits(speeds.Substring(1, 1)),ToDigits(speeds.Substring(0, 1)),0,0,0,0}
                        For LtSwLEDWriteSpeedCounter=1 to 5
                           MW3.SendGenericOutput(MyDevice,AltOutputReport)
                        Next
                        lastspeed=speeds
                     End If
                  LtSwLEDDisplayCounter=0
                  LtSwLEDWriteSpeedCounter=0
                  LtSwWriteToLED=False
               Else 'Do not write to LEDs
               End If
               LtSwWriteToLED=False
            Else 'The switch is in the same position as last time so do not run the code
            End if
         Else
         End If 
         lever(6).LastValue=AnalogValue(0)
      End Select 'Analog Check End [/MWTAG13]
 Samwolf wrote:Thanks for working on this George.![]()
Hopefully RS and Raildriver can get together and resolve this long outstanding issue someday.
Users browsing this forum: No registered users and 0 guests