Solarus quests  1.6
Quest maker's reference
Inputs

You can get information about the low-level keyboard and joypad inputs through sol.input.

But remember that when a low-level keyboard or joypad input event occurs, all useful objects (sol.main, the game, map and menus) are already notified. For example, when the user presses a keyboard key, the engine automatically calls sol.main:on_key_pressed().

Also note that during the game, there exists the higher-level notion of game commands to ease your life.

Functions of sol.input

sol.input.is_joypad_enabled()

Returns whether joypad support is enabled.

This may be true even without any joypad plugged.

  • Return value (boolean): true if joypad support is enabled.

sol.input.set_joypad_enabled([joypad_enabled])

Enables or disables joypad support.

Joypad support may be enabled even without any joypad plugged.

  • joypad_enabled true to enable joypad support, false to disable it. No value means true.

sol.input.is_key_pressed(key)

Returns whether a keyboard key is currently down.

  • key (string): The name of a keyboard key.
  • Return value (boolean): true if this keyboard key is currently down.

sol.input.get_key_modifiers()

Returns the keyboard key modifiers currently active.

  • Return value (table): A table whose keys indicate what modifiers are currently down. Possible table keys are "shift", "control", "alt" and "caps lock". Table values are true.

sol.input.is_joypad_button_pressed(button)

Returns whether a joypad button is currently down.

  • button (number): Index of a button of the joypad.
  • Return value (boolean): true if this joypad button is currently down.

sol.input.get_joypad_axis_state(axis)

Returns the current state of an axis of the joypad.

  • axis (number): Index of a joypad axis. The first one is 0.
  • Return value (number): The state of that axis. -1 means left or up, 0 means centered and 1 means right or down.

sol.input.get_joypad_hat_direction(hat)

Returns the current direction of a hat of the joypad.

  • hat (number): Index of a joypad hat. The first one is 0.
  • Return value (number): The direction of that hat. -1 means that the hat is centered. 0 to 7 indicates that the hat is in one of the eight main directions.

sol.input.get_mouse_position()

Returns the current position of the mouse cursor relative to the quest size.

If the mouse is outside the window, mouse coordinates are captured only if a mouse button is pressed. In this case, the returned values can be out of bounds of the quest size and can be negative. This allows you to keep track of the mouse movement when dragging something. Otherwise, when no mouse button is pressed, the returned coordinates are the last position of the mouse in the window.

  • Return value 1 (integer): The x position of the mouse in quest size coordinates.
  • Return value 2 (integer): The y position of the mouse in quest size coordinates.

sol.input.is_mouse_button_pressed(button)

Returns whether a mouse button is currently down.

  • button (string): The name of a mouse button. Possible values are "left", "middle", "right", "x1" and "x2".
  • Return value (boolean): true if mouse button is down.

sol.input.get_finger_position(finger)

Returns the current position of a finger if it exists.

  • finger (integer): The finger id to check.
  • Return value 1 (integer): The x position of the finger in quest size coordinates. Return nil if the finger does not exist or is not pressed.
  • Return value 2 (integer): The y position of the finger in quest size coordinates.

sol.input.get_finger_pressure(finger)

Returns the current pressure of a finger if it exists.

  • finger (integer): The finger id to check.
  • Return value 1 (number): The pressure of the finger between 0.0 and 1.0. Return nil if there is no such finger.

sol.input.is_finger_pressed(finger)

Returns whether a finger is currently pressed.

  • finger (integer): The finger id to check.
  • Return value (boolean): true if the finger is down.

sol.input.simulate_key_pressed(key)

Simulates pressing a keyboard key.

  • key (string): The keyboard key to simulate.

sol.input.simulate_key_released(key)

Simulates releasing a keyboard key.

  • key (string): The keyboard key to simulate.