Class GInput

This class represents an input handler. An input handler receives mouse and keyboard information, and makes it available to the user. To access mouse information, simply access the attribute touch. To access keyboard information, use the method is_key_down.

You should never construct an object of this class. Creating a new instance of this class will not properly hook it up to the keyboard and mouse. Instead, you should only use the one provided in the input attribute of GameApp. See that class for more information.

Constructor

class game2d.GInput

A class representing an input handler

An input handler receives mouse and keyboard information, and makes it available to the user. To access mouse information, simply access the attribute touch. To access keyboard information, use the method is_key_down().

You should never construct an object of this class. Creating a new instance of this class will not properly hook it up to the keyboard and mouse. Instead, you should only use the one provided in the input attribute of GameApp. See the documentation of that class for more information.

Attributes

GInput.touch_enabled

Whether the touch (mouse) interface is currently enabled.

Setting this value to False will disable all mouse clicks or drags. The value is True by default.

Invariant: Must be a bool

GInput.keyboard_enabled

Whether the keyboard interface is currently enabled.

Setting this value to False will disable all key presses. The value is True by default.

Invariant: Must be a bool

Immutable Attributes

GInput.touch

The current (x,y) coordinate of the mouse, if pressed.

This method only returns coordinates if the mouse button is pressed. If the mouse button is not pressed it returns None. The origin (0,0) corresponds to the bottom left corner of the application window.

There is currently no way to get the location of the mouse when the button is not pressed. This a limitation of Kivy.

Immutable: This value cannot be altered.

Invariant: Must be either a Point2 or None (if there is no touch).

GInput.key_count

The number of keys currently held down.

This attribute is a quick way to check whether the user has pressed any keys.

Immutable: This value cannot be altered.

Invariant: Must be an int > 0.

GInput.keys

The list of keys that are currently held down.

Using this attribute is much slower than the method is_key_down(). You should use that method when you want to test a specific key. This attribute is primarily for debugging.

Immutable: This value cannot be altered.

Invariant: Must be a list of strings (possibly empty)

Methods

GInput.is_key_down(key)

Checks wether the key is currently held down.

The key is a string describing the key pressed. For example, to determine whether the right-arrow key is pressed, use the method call:

input.is_key_down('right')

Similarly the method call:

input.is_key_down('w')

will indicate whether the W key is pressed.

For a complete list of key names, see the Kivy documentation.

Parameters

key (str) – the key to test

Returns

True if key is currently held down

Return type

bool

GInput.is_touch_down()

Checks wether the mouse is currently held down.

If this method returns True, the attribute touch is guaranteed to not be None.

Returns

True if the mouse is currently held down; False otherwise

Return type

bool

Return to top level