MaSzyna International > EU07 Simulator English forum

 Driving with joystick

(1/2) > >>

Greno Zee:
Even though the control of MaSzyna are well organized for train driving, since I play only from laptop, I wondered how I could simplify the numpad controls (the Fn key combinations are not so wow).
My other reason was watching all those handle controls in the cabins and having a sort of handle controller (joystick) next to me just wasted - it simply called for a solution.

To use a joystick with MaSzyna you need AutoHotkey. Just download the installer from here. The installation process is plain simple.
Once installed, create anywhere on your PC (ideally in the MaSzyna folder) a file with extension AHK - say "MaSzyna Joystick.ahk".
Now copy this code into the file:

--- Kod: ---; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         Greno Zee
;
; Script Function:
;   Provides joystick control for MaSzyna train simulator
;

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent  ; Keep this script running until the user explicitly exits it.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
CheckInterval = 10 ; Number of miliseconds between joystick status checks. It's prefered not to change this value
ChecksForShift = 50 ; Number of check the joystick must be in certain position to trigger the SHIFT + Key input.

ShiftCounter := 0
SetTimer, WatchAxis, %CheckInterval%
return

WatchAxis:
GetKeyState, JoyX, JoyX  ; Get position of X axis.
GetKeyState, JoyY, JoyY  ; Get position of Y axis.
GetKeyState, Joy1, Joy1  ; Get button 1 state.
GetKeyState, Joy2, Joy2  ; Get button 2 state.

KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).

if JoyX > 70
{
    if Joy1 = D
        KeyToHoldDown = Numpad7
    else if Joy2 = D
        KeyToHoldDown = NumpadDot
    else
        KeyToHoldDown = Numpad9
}
else if JoyX < 30
{
    if Joy1 = D
        KeyToHoldDown = Numpad1
    else if Joy2 = D
        KeyToHoldDown = Numpad0
    else
        KeyToHoldDown = Numpad3
}
else if JoyY > 70
{
    if Joy1 = D
        KeyToHoldDown = NumpadMult
    else if Joy2 = D
        KeyToHoldDown = r
    else
        KeyToHoldDown = NumpadSub
}
else if JoyY < 30
{
    if Joy1 = D
        KeyToHoldDown = NumpadDiv
    else if Joy2 = D
        KeyToHoldDown = d
    else
        KeyToHoldDown = NumpadAdd
}
else
    KeyToHoldDown =

SetKeyDelay -1  ; Avoid delays between keystrokes.

if KeyToHoldDown   ; There is a key to press down.
{
    if KeyToHoldDown = %KeyToHoldDownPrev%
    {
        ShiftCounter += 1

        if ShiftCounter = %ChecksForShift%
        {
            SendInput {Shift Down}
            Sleep 70
            SendInput {%KeyToHoldDown%}
            Sleep 70
            SendInput {Shift Up}
        }
    }
    else
        SendInput {%KeyToHoldDown%}
}
else
    ShiftCounter := 0
return

--- Koniec kodu ---


Then double-click the file, start MaSzyna and enjoy!

The joystick controls are like this:
Forward: master controller +
Forward + button 1: field shunt +
Forward + button 2: reverser forward

Backward: master controller -
Backward + button 1: field shunt -
Backward + button 2: reverser backward

Left: extend main brake
Left + button 1: extend aid brake
Left + button 2: emergency brake

Right: release main brake
Right + button 1: release aid brake
Right + button 2: main brake quick release.

Holding the joystick in certain position does not cause any controls to be repeated. Instead, after half a second (this is an easily adjustable value) in certain position the script send a SHIFT + Key command.
So for instance if you hold the button 1 and push forward, the field shunt will jump one position forwards and after half a second it jumps to max.
These scripts are easy to adjust. If you figure out a better mapping, post here please so we can extend our driving experience!

iwan:

--- Cytat: "Greno Zee" ---To use a joystick with MaSzyna you need AutoHotkey.
--- Koniec cytatu ---


Good job! Thanks!

Veµmi presný článok ;) Díky

Greno Zee:
Even though I perfectly understand this last request, I can't satisfy it. But I'm sure someone else can put a translated copy to the polish section.

Btw, I'm gaining some experience with this and I'll probably tweak the script a bit. I plan on making the brake control respond only once per joystick move and the same probably for the field shunt.

Greno Zee:
Modified the script in original post to provide more intuitive control. Basically, repetitive keystrokes have been removed and holding the joystick in certain position causes the SHIFT + Key to be pressed.

RooteK:
Can you read, what to drive with steering wheel?? I don't have a Joystick. I have steering wheel.

Nawigacja

[0] Indeks wiadomo¶ci

[#] Następna strona

IdĽ do wersji pełnej
Powered by Advanced Topic Prefix Pro
Powered by SMFPacks Likes Pro Mod