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 the class GameApp for more information.
Constructor¶
-
game2d.
GInput
¶ Constructor: Creates a new input handler
This constructor does very little. It does not hook up the handler to the mouse or keyboard. That functionality happens behind the scenes with hidden methods. You should only use use the object provided in the input attribute of GameApp. See the class GameApp for more information.
Attributes¶
-
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
-
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¶
-
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 GPoint or None (if there is no touch).
-
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.
-
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¶
-
is_key_down
(key)¶ Returns: True if 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.
Parameter: key – the key to test Precondition: Must be a string.
-
is_touch_down
()¶ Returns: True if the mouse is currently held down.
If this method returns True, the attribute touch is guaranteed to not be None.