Copyright by Jonathan S. Harbour

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 8. Keyboard and Mouse Input

The keyboard and mouse are the only realistic devices for user input in a Java game, regardless of whether it’s a web-based applet or a standalone application. But even when considering a standard Windows-based game developed in DirectX or another library, the keyboard and mouse are by far the most common forms of user interaction in a game. This chapter covers the important subject of handling user input.

Here are the key topics you will learn in this chapter:

  • Listening for keyboard events

  • Testing keyboard input

  • Displaying key presses

  • Reading mouse motion

  • Detecting mouse buttons

  • Testing mouse input

Listening to the User

Java provides an interesting way to interact with users through a series of listener methods. You ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required