Skip to content
badlogic edited this page Sep 14, 2013 · 2 revisions

Different platforms have different input facilities. On the desktop users can talk to your application via the keyboard and a mouse. The same is true for browser based games. On Android, the mouse is replaced with a (capacitive) touch screen, and a hardware keyboard is often missing. All (compatible) Android devices also feature an accelerometer and sometimes even a compass (magnetic field sensor).

Libgdx abstract all these different input devices. Mouse and touch screens are treated as being the same, with mice lacking multi-touch support (they will only report a single "finger") and touch-screens lacking button support (they will only report "left button" presses).

Depending on the input device, one can either [poll](http://en.wikipedia.org/wiki/Polling_(computer_science\)) the state of a device periodically, or register a listener that will receive input events in chronological order. The former is sufficient for many arcade games, e.g. analogue stick controls, the later is necessary if UI elements such as buttons are involved, as these rely on event sequences such as touch down/touch up.

All of the input facilities are accessed via the Input module.

   // Check if the A key is pressed
   boolean isPressed = Gdx.input.isKeyPressed(Keys.A);

Table of Contents

a note from the translation

Wiki Style Guide

Clone this wiki locally