1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Mouse and Keyboard Input in Gosu


2 of 5

Key and Button Constants
Mouse and Keyboard Input in Gosu

Behind the scenes, buttons are represented by integers. These integer codes are platform-dependent and probably shouldn't find their way into your game code. To abstract this away, Gosu provides a number of constants to use.

For every keyboard key, there is a Gosu::Kb* constant. For most of the keys, the names of these constants are easily guessed. For example, the arrow keys are Gosu::KbLeft, Gosu::KbRight, Gosu::KbUp and Gosu::KbDown. For a complete list, see the documentation for the Gosu module.

There are also similar constants for mouse buttons. You'll mainly be using the Gosu::MsLeft and Gosu::MsRight for left and right click. There is also support for gamepads via the Gosu::Gp* constants.

This article is part of a series. Read more articles about Rapid Game Prototyping in Ruby

©2014 About.com. All rights reserved.