meta data for this page
InputMapper.lua
InputMapper is responsible for managing in-game input, as well as for remapping input. It is possible to add and remap new keys in mods.
InputMapper:setup()
Is called while the game is initialising. The keys listed below are all keys that are registered in the vanilla game.
You can add new keys or axes yourself by calling InputMapper:addKey()
or InputMapper.addAxis()
as demonstrated below.
37 38 function InputMapper:setup() 39 -- setup default keys 40 41 InputMapper:addKey("Ingame", "Hotkey_IngameMenu", "Escape"); 42 InputMapper:addKey("Ingame", "Hotkey_Minimap", "F2"); 43 InputMapper:addKey("Ingame", "IngameMenu_refresh", "F5"); 44 InputMapper:addKey("Ingame", "Hotkey_DashboardMenu", "Backspace"); 45 InputMapper:addKey("Ingame", "TakeScreenshot", "SysReq"); 46 InputMapper:addKey("Ingame", "HideHUDAndUI", ""); 47 InputMapper:addKey("Ingame", "UI_Scroll_Up", "PageUp"); 48 InputMapper:addKey("Ingame", "UI_Scroll_Down", "PageDown"); 49 InputMapper:addKey("Ingame", "Interaction", "Q"); 50 51 -- scrolling UP is positive, scrolling DOWN is negative 52 InputMapper:addAxis("Ingame", "Axis_UI_Scroll", "UI_Scroll_Up", "UI_Scroll_Down", "Mouse ScrollWheel", false, false, true, true); 53 54 InputMapper:addKey("Ingame", "Look_Up", "UpArrow"); 55 InputMapper:addKey("Ingame", "Look_Down", "DownArrow"); 56 InputMapper:addKey("Ingame", "Look_Left", "LeftArrow"); 57 InputMapper:addKey("Ingame", "Look_Right", "RightArrow"); 58 InputMapper:addKey("Ingame", "Look_Zoom_In", "PageUp"); 59 InputMapper:addKey("Ingame", "Look_Zoom_Out", "PageDown"); 60 InputMapper:addKey("Ingame", "Spectator_Faster", "LeftShift"); 61 InputMapper:addKey("Ingame", "Spectator_Slower", "LeftControl"); 62 InputMapper:addKey("Ingame", "Walk_Forward", "W"); 63 InputMapper:addKey("Ingame", "Walk_Backward", "S"); 64 InputMapper:addKey("Ingame", "Walk_Left", "A"); 65 InputMapper:addKey("Ingame", "Walk_Right", "D"); 66 InputMapper:addKey("Ingame", "Walk_Up", "Q"); 67 InputMapper:addKey("Ingame", "Walk_Down", "E"); 68 69 InputMapper:addKey("Ingame", "Throw_Snow_Ball", "Z"); 70 71 InputMapper:addAxis("Ingame", "Axis_Look_UpDown", "Look_Up", "Look_Down", "Mouse Y", false, false); 72 InputMapper:addAxis("Ingame", "Axis_Look_LeftRight", "Look_Left", "Look_Right", "Mouse X", false, false, true); 73 InputMapper:addAxis("Ingame", "Axis_Look_Zoom", "Look_Zoom_In", "Look_Zoom_Out", "Mouse ScrollWheel",false, false, false, true); 74 InputMapper:addAxis("Ingame", "Axis_Walk_Forward", "Walk_Forward", "Walk_Backward", nil, false, false); 75 InputMapper:addAxis("Ingame", "Axis_Walk_Sideways", "Walk_Left", "Walk_Right", nil, false, false, true); 76 InputMapper:addAxis("Ingame", "Axis_Walk_UpDown", "Walk_Up", "Walk_Down", nil, false, false); 77 78 InputMapper:addKey("Ingame", "Sprint", "LeftShift"); 79 InputMapper:addKey("Ingame", "Jump", "Space"); 80 InputMapper:addKey("Ingame", "PocketLamp", "L"); 81 InputMapper:addKey("Ingame", "EnterSeat", "E"); 82 InputMapper:addKey("Ingame", "InterieurCamera", "Alpha1"); 83 InputMapper:addKey("Ingame", "ExterieurCamera", "Alpha2"); 84 InputMapper:addKey("Ingame", "CustomCamera1", "Alpha3"); 85 InputMapper:addKey("Ingame", "CustomCamera2", "Alpha4"); 86 InputMapper:addKey("Ingame", "Scenario_TimescaleFaster", "KeypadPlus"); 87 InputMapper:addKey("Ingame", "Scenario_TimescaleSlower", "KeypadMinus"); 88 InputMapper:addKey("Ingame", "Scenario_TimescaleBoost", ""); 89 90 91 InputMapper:addKey("Vehicle", "Vehicle_Accelerate_Key", "W"); 92 InputMapper:addKey("Vehicle", "Vehicle_Brake_Key", "S"); 93 InputMapper:addKey("Vehicle", "Vehicle_Steer_Left", "A"); 94 InputMapper:addKey("Vehicle", "Vehicle_Steer_Right", "D"); 95 96 InputMapper:addAxis("Vehicle", "Axis_Vehicle_Throttle_Brake_Combined", "Vehicle_Accelerate_Key", "Vehicle_Brake_Key", nil, false, true); 97 InputMapper:addAxis("Vehicle", "Axis_Vehicle_Throttle", "Vehicle_Accelerate_Key", "", nil, true, true); 98 InputMapper:addAxis("Vehicle", "Axis_Vehicle_Brake", "Vehicle_Brake_Key", "", nil, true, true); 99 InputMapper:addAxis("Vehicle", "Axis_Vehicle_Steer", "Vehicle_Steer_Left", "Vehicle_Steer_Right", nil, false, false, true); 100 101 InputMapper:addKey("Vehicle", "Vehicle_Switch", "Tab"); 102 InputMapper:addKey("Vehicle", "Vehicle_Switch_Inverse", "LeftControl Tab"); 103 InputMapper:addKey("Vehicle", "Vehicle_Attach", "Q"); 104 InputMapper:addKey("Vehicle", "Vehicle_RefillFuel", "U"); 105 --InputMapper:addKey("Vehicle", "Vehicle_AutomaticDrive", "G"); 106 InputMapper:addKey("Vehicle", "Vehicle_EnableCruiseControl", "O"); 107 InputMapper:addKey("Vehicle", "Vehicle_InverseDirection", "LeftShift", "Mouse2"); 108 InputMapper:addKey("Vehicle", "Vehicle_StartMotor", "KeypadEnter"); 109 InputMapper:addKey("Vehicle", "Vehicle_ParkingBrake", "B"); 110 InputMapper:addKey("Vehicle", "Vehicle_Lights", "L"); 111 InputMapper:addKey("Vehicle", "Vehicle_BeaconLight", "Home"); 112 InputMapper:addKey("Vehicle", "Vehicle_WorkLight1", "Keypad4"); 113 InputMapper:addKey("Vehicle", "Vehicle_WorkLight2", "Keypad5"); 114 InputMapper:addKey("Vehicle", "Vehicle_WorkLight3", "Keypad6"); 115 InputMapper:addKey("Vehicle", "Vehicle_WarningSound", "Space"); 116 InputMapper:addKey("Vehicle", "VehicleCar_IndicatorLeft", "Keypad1"); 117 InputMapper:addKey("Vehicle", "VehicleCar_HazardLights", "Keypad2"); 118 InputMapper:addKey("Vehicle", "VehicleCar_IndicatorRight", "Keypad3"); 119 InputMapper:addKey("Vehicle", "VehicleSnowcat_LowerGroomer", "V"); 120 InputMapper:addKey("Vehicle", "VehicleSnowcat_LockTrail", "C"); 121 InputMapper:addKey("Vehicle", "VehicleSnowcat_LeftFlap", "Y"); 122 InputMapper:addKey("Vehicle", "VehicleSnowcat_RightFlap", "X"); 123 InputMapper:addKey("Vehicle", "VehicleSnowcat_TenseWinch", "P"); 124 InputMapper:addKey("Vehicle", "VehicleSnowcat_TurnWinchLeft", "N"); 125 InputMapper:addKey("Vehicle", "VehicleSnowcat_TurnWinchRight", "M"); 126 InputMapper:addKey("Vehicle", "VehicleSnowcat_TurnGroomerLeft", "H"); 127 InputMapper:addKey("Vehicle", "VehicleSnowcat_TurnGroomerRight", "J"); 128 InputMapper:addKey("Vehicle", "SnowCannon_TurnOnOff", "B"); 129 InputMapper:addKey("Vehicle", "SnowCannon_RotateLeft", "C"); 130 InputMapper:addKey("Vehicle", "SnowCannon_RotateRight", "V"); 131 InputMapper:addKey("Vehicle", "SnowCannon_RotateUp", "R"); 132 InputMapper:addKey("Vehicle", "SnowCannon_RotateDown", "F"); 133 134 InputMapper:addAxis("Vehicle", "Axis_Snowcat_Blade_UpDown", nil, nil, nil, false, false); 135 InputMapper:addAxis("Vehicle", "Axis_Snowcat_Blade_LeftRight", nil, nil, nil, false, false); 136 InputMapper:addAxis("Vehicle", "Axis_Snowcat_Blade_Tilt", nil, nil, nil, false, false); 137 InputMapper:addAxis("Vehicle", "Axis_Snowcat_Blade_AttackAngle", nil, nil, nil, false, false); 138 InputMapper:addAxis("Vehicle", "Axis_Snowcat_Blade_LeftWing", nil, nil, nil, false, false); 139 InputMapper:addAxis("Vehicle", "Axis_Snowcat_Blade_RightWing", nil, nil, nil, false, false); 140 141 InputMapper:addKey("Ropeway", "RW_PushCarrier", "R"); 142 InputMapper:addKey("Ropeway", "RW_PullCarrier", "F"); 143 InputMapper:addKey("Ropeway", "RW_StopCarrier", "G"); 144 InputMapper:addKey("Ropeway", "RW_Bar", "N"); 145 InputMapper:addKey("Ropeway", "RW_Bubble", "M"); 146 147 InputMapper:addKey("Ropeway", "RW_Remote_Stop", "H"); 148 InputMapper:addKey("Ropeway", "RW_Remote_EmergencyStop", "G"); 149 InputMapper:addKey("Ropeway", "RW_Remote_Forward", "R"); 150 InputMapper:addKey("Ropeway", "RW_Remote_Backward", "F"); 151 InputMapper:addKey("Ropeway", "RW_Remote_Reset", "J"); 152 InputMapper:addKey("Ropeway", "RW_Remote_Start", "K"); 153 InputMapper:addKey("Ropeway", "RW_Remote_Faster", "W"); 154 InputMapper:addKey("Ropeway", "RW_Remote_Slower", "S"); 155 156 InputMapper:addKey("Skiing", "SK_RotateLeft", "A"); 157 InputMapper:addKey("Skiing", "SK_RotateRight", "D"); 158 InputMapper:addKey("Skiing", "SK_SlowDown", "S"); 159 InputMapper:addKey("Skiing", "SK_PushLeft", "Q"); 160 InputMapper:addKey("Skiing", "SK_PushRight", "E"); 161 162 InputMapper:addKey("Editor", "Editor_Move_Camera", "Space", "LeftAlt"); 163 InputMapper:addKey("Editor", "Editor_NewObject", "LeftControl N"); 164 InputMapper:addKey("Editor", "Editor_Spin_Object_Right", "R"); 165 InputMapper:addKey("Editor", "Editor_Spin_Object_Left", "F"); 166 InputMapper:addKey("Editor", "Editor_Free_Place", "B"); 167 InputMapper:addKey("Editor", "Editor_Instantiate_Selection", "Tab"); 168 InputMapper:addKey("Editor", "Editor_Instantiate_Selection_InPlace", "LeftControl Tab"); 169 InputMapper:addKey("Editor", "Editor_Delete", "Delete", "Backspace"); 170 InputMapper:addKey("Editor", "Editor_GizmoMode_Move", "Alpha1"); 171 InputMapper:addKey("Editor", "Editor_GizmoMode_Rotate", "Alpha2"); 172 InputMapper:addKey("Editor", "Editor_GizmoMode_Scale", "Alpha3"); 173 InputMapper:addKey("Editor", "Editor_GizmoMode_Combined", "Alpha4"); 174 InputMapper:addKey("Editor", "Editor_Brush_Larger", "V"); 175 InputMapper:addKey("Editor", "Editor_Brush_Smaller", "C"); 176 InputMapper:addKey("Editor", "Editor_Brush_Strength_Up", "R"); 177 InputMapper:addKey("Editor", "Editor_Brush_Strength_Dn", "F"); 178 InputMapper:addKey("Editor", "Editor_Terrain_LMB", "Mouse0"); 179 InputMapper:addKey("Editor", "Editor_Terrain_MMB", "Mouse2"); 180 InputMapper:addKey("Editor", "Editor_Terrain_RMB", "Mouse1"); 181 InputMapper:addKey("Editor", "Editor_Increase_Nav_Speed", "PageUp"); 182 InputMapper:addKey("Editor", "Editor_Decrease_Nav_Speed", "PageDown"); 183 184 -- refresh input 185 -- do not call this from mods 186 SettingsManager:loadInput(); 187 end;
InputMapper:addKey(category, key, keyCode1, keyCode2, keyCode3)
Adds a key to Input mapper using following parameters:
category
(string): category, in which the key belongs. See above for examples.key
(string): name of the key. Should be descriptive but not too long.keyCode1
(string): default mapped key code. See this list from the Unity documentation to find out which key codes are allowed.keyCode2 = nil
(string): same, but optional.keyCode3 = nil
(string): same, but optional.
If one of the three key codes is hit, the key will be considered as pressed.
Tip: KeyCode A B
will require the user to press the keys A
and B
simultaneously.
function InputMapper:addKey(category, key, keyCode1, keyCode2, keyCode3)
InputMapper:addAxis(category, axis, keyHigh, keyLow, axisCode, singleSided, invert, invertKeys, onlyOnKeyDown, sensitivity)
Adds an axis to Input mapper using following parameters:
category
(string): category, in which the axis belongs. See above for examples.key
(string): name of the axis. Should be descriptive but not too long, and should start withAxis_
.keyHigh
(string): if this key is pressed, the axis will return 1. (You have to register the key beforehand usingInputMapper:addKey()
). Usenil
to disable.keyLow
(string): same again, but this time the axis will return -1. Usenil
to deactivate.axisCode
(string): default mapped axis code. Can be either“Mouse X”
,“Mouse Y”
,“Mouse ScrollWheel”
or one of“Joy1Axis1”
to“Joy16Axis29”
.singleSided = false
(bool, optional):true
if the axis is single sided, i.e. ranges from 0 to 1 (instead of -1 to 1, which is two-sided).invert = false
(bool, optional):true
if the joystick axis shall be inverted by default.invertKeys = false
(bool, optional):true
ifkeyHigh
andkeyLow
shall be swapped internally.onlyOnKeyDown = false
(bool, optional):true
if the key shall only be considered in the frame the player starts pressing it. This is a very rare use case.sensitivity = 1
(float, optional): Scales how fast the axis reacts to joystick movement or key pressing.
If one of the keys is hit, the axis will take their respective value. Otherwise, the joystick's value will be returned.
function InputMapper:addAxis(category, axis, keyHigh, keyLow, axisCode, singleSided, invert, invertKeys, onlyOnKeyDown, sensitivity)
InputMapper:getKey(keyData, ignoreBlockInput)
Returns whether the key keyData
(table) is currently being pressed. keyData
should always be something like InputMapper.Hotkey_IngameMenu
or any other key.
ignoreBlockInput
is for internal use only and should not be used (do not pass this argument over from mods).
This is comparable to Unity's Input.GetKey (but extended by some remapping features).
function InputMapper:getKey(keyData, ignoreBlockInput)
InputMapper:getKeyDown(keyData, ignoreBlockInput)
Returns true only in the frame in which the key keyData
(table) starts to be pressed. In most cases, this is a safe option for keys that toggle some features on/off. Again, keyData
should always be something like InputMapper.Hotkey_IngameMenu
or any other key.
ignoreBlockInput
is for internal use only and should not be used (do not pass this argument over from mods).
This is comparable to Unity's Input.GetKeyDown (but extended by some remapping features).
function InputMapper:getKeyDown(keyData, ignoreBlockInput)
InputMapper:getKeyUp(keyData, ignoreBlockInput)
Returns true only in the frame in which the key keyData
(table) is released. This will usually be in use only rarely. One more time, keyData
should always be something like InputMapper.Hotkey_IngameMenu
or any other key.
ignoreBlockInput
is for internal use only and should not be used (do not pass this argument over from mods).
This is comparable to Unity's Input.GetKeyUp (but extended by some remapping features).
function InputMapper:getKeyUp(keyData, ignoreBlockInput)
InputMapper:getAxis(axis, joystickOnly, ignoreBlockInput, ignoreLock)
Returns the value of the input axis axis
(table). The return value is a float between -1 and 1 or 0 and 1, depending on singleSided
when calling InputMapper:addAxis()
. Set joystickOnly
(bool) to true
if you only want to consider joysticks but not keys (rare use case).
ignoreBlockInput
and ignoreLock
are for internal use only and should not be used (do not pass this argument over from mods).
axis
should always be something like InputMapper.Axis_Walk_Forward
or any other axis.
function InputMapper:getAxis(axis, joystickOnly, ignoreBlockInput, ignoreLock)
InputMapper:getAxisRange(axis)
Returns the range of the axis axis
(table), which will be either a tuple 0, 1
in case the axis is single sided or -1, 1
otherwise. Note that whichever value is assigned to sensitivity
is ignored for this calculation, the function will always return 0, 1
or -1, 1
.
axis
should always be something like InputMapper.Axis_Walk_Forward
or any other axis.
function InputMapper:getAxisRange(axis)
InputMapper:replaceKeyCodesInText(text)
Returns the string text
, but replaces all occurences of $Input(Hotkey_IngameMenu)
in this text by the respective key assignment. In this case, this would be the key assigned to InputMapper.Hotkey_IngameMenu
, which will usually be “Escape”
.
The rest of the text stays unchanged.
function InputMapper:replaceKeyCodesInText(text)
InputMapper:getKeyCode(code)
Returns the assigned key to the code code
(attention, this time a string!).
InputMapper:getKeyCode(“Hotkey_IngameMenu”)
will usually return “Escape”
.
function InputMapper:getKeyCode(code)
Copyright
All contents of this page may be used for modding use for Winter Resort Simulator - Season 2 only. Any use exceeding this regulation is not permitted.
Copyright (C) HR Innoways, 2021. All Rights Reserved.