Skip to main content

Inputs

What makes your game a game is that the players can control the outcome. They do this using inputs. Easel supports multiple input methods, including the mouse, keyboard, touchscreens and gamepads. You can also simulate input (normally used for bot players), and remap controls. This page gives you an overview of all of these topics.

Button presses

The ButtonDown, ButtonUp and IsButtonDown functions signal when a particular button is pressed by a particular player. Buttons can be keyboard keys, mouse buttons, gamepad buttons or touchscreen taps. See Keycodes for a full list of all possible buttons that can be pressed.

Remapping

The KeyRebindingBlock user interface element allows a player to remap keys. When they select the elemet, the player can choose a new key they would like to press instead of the original key.

Unifying inputs

ButtonRemap is a way to introduce a remapping programmatically. It can be used to provide additional ways to trigger a particular key. For example, a game might normally require a player to press Spacebar to jump, but ButtonRemap(Click, KeySpacebar) would allow the player to jump by clicking the mouse as well.

tip

Nominate one of your inputs to be the canonical input, e.g. KeySpacebar to make your character jump. Use ButtonRemap to support alternative input methods, for example ButtonRemap(Click, KeySpacebar) to support the mouse, and ButtonRemap(Click, GamepadA) to support gamepads. Put all your ButtonRemaps at the top of your Main function and then listen to the canonical input for the rest of your codebase.

Key remappings are handled transparently by the engine. The actual key that was pressed will be translated to the remapped key and only the remapped key will be signalled. The Easel program never receives the actual key pressed and does not need to be aware of the remapping.

Pointers

Normally a pointer refers to a mouse.

The Pointer prop contains the last position of a player's mouse pointer. The IsPointerActive property will be true if the mouse is within the boundaries of the game window, and false otherwise.

The TouchscreenVirtualPointer function can make the game simulate a virtual mouse pointer from the player's touch. Any swipes across the screen will be translated to relative movements of the virtual mouse pointer. When the player is using a touchscreen as the pointer, IsPointerActive will only be true if the player is currently touching the screen.

Touchscreens

The TouchscreenMode function can be used to determine whether a player is using a touchscreen device. Sometimes the value will be undefined initially as it requires waiting the user to use their mouse or touch the screen before it can be determined. You can await TouchscreenMode to watch for any changes to this property.

Clicks vs Taps

The Click keycode specifically refers to a click from a mouse, whereas Tap keycode specifically only handles taps to a touchscreen. This allows you to distinguish the two forms of input.

If your codebase only refers to Click and never Tap, a Tap will be auto-remapped to Click (same as doing ButtonRemap(Tap, Click)). The same applies vice versa - i.e. there will be an implicit ButtonRemap(Click, Tap) if Click is never used.

Touchscreen only UI elements

The TouchscreenOnly/NonTouchscreenOnly UI layout elements let you show elements of the UI only to either touchscreen or non-touchscreen users. This allows you to display relevant instructions to that player's input device, for example telling the player to "tap" if they are on a touchscreen but "click" if they are not.

Gamepads

The IsGamepadConnected function can be used to determine whether a gamepad is connected. Gamepad may not be supported on all devices and all platforms. Currently Google Chrome has the best support for gamepads. Gamepads may also have differing layouts and capabilities.

Gamepads can have up to two joysticks, these can be read using the Joystick and Joystick2 functions. The VirtualJoystick and VirtualJoystick2 functions allow you to create a simulated on-screen joystick for mouse or touchscreen users. The KeyboardVirtualJoystick function allows you to map keyboard keys to a virtual joystick. This can be used to support common control schemes like WASD or Arrow keys in a unified manner.

Simulating input

A common method for implementing bot players is to simulate input. This can be done by simply calling the same functions that are used to signal input from a real player. Pointers can be simulated by assigning to the Pointer or IsPointerActive props. Button presses can be simulated by calling ButtonDown or ButtonUp. Joystick movements can be simulated by setting the Joystick or Joystick2 props.