Detecting keyboard, D-Pad, and Trackball events

The most common input device among all is the keyboard. This is true for Android too. An Android keyboard can be physical: in the device front face (like traditional Blackberries) or on a slide-out screen. However, a keyboard is more commonly virtual, that is, emulated on the screen at the cost of a large portion of space taken. In addition to the keyboard itself, every Android device must include a few physical or emulated buttons such as Menu, Home, and Tasks.

A much less common type of input device is the Directional-Pad. A D-Pad is a set of physical buttons to move up, down, left, or right and a specific action/confirmation button. Although they often disappear from recent phones and tablets, D-Pads remain one of the most convenient ways to move across text or UI widgets. D-Pads are often replaced by trackballs. Trackballs behave similarly to a mouse (the one with a ball inside) that would be upside down. Some trackballs are analogical, but others (for example, optical ones) behave as a D-Pad (that is, all or nothing).

Detecting keyboard, D-Pad, and Trackball events

To see how they work, let's use these peripherals to move our space ship in DroidBlaster. The Android NDK now allows handling all these input peripherals on the native side. So, let's try them!

Note

The resulting project is provided with this book under the name DroidBlaster_Part14.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.109.30