Handling Events
In order to handle events in Cave (to see if the user pressed a keyboard or mouse key), you'll need to use the cave.Events
class. Note that you cannot instantiace your own Events class, instead of this, you can get the engine's events class instance by calling this function:
events = cave.getEvents()
cave.Events
Here is an example of the cave Events system in action:
events = cave.getEvents()
if events.pressed(cave.event.KEY_W):
print("The user pressed the key W!")
# You can also use the event names (as strings):
if events.pressed("S"):
print("The user pressed the key S!")
# Mouse events works the same way:
if events.released(cave.event.MOUSE_LEFT):
print("The user released the left mouse button!")
Note: Again, do not instantiate a new instance of this class, you should always use the one provided by the cave.getEvents()
function.
Methods
pressed(event : str) -> bool
pressed(event : cave.event) -> bool
Returns True if the user just pressed the event key or False if not.
active(event : str) -> bool
active(event : cave.event) -> bool
Always returns True while the user is pressing the event key or False if not.
released(event : str) -> bool
released(event : cave.event) -> bool
Returns True if the user just released the event key or False if not.
The following methods are related to mouse specific behaviours:
setRelativeMouse(value: bool)
When enabled, the mouse will be invisible and the mouse motion will be computed (and available at GetMouseMotion()), but not applied to the mouse cursor.
If enabled, then if you want to know how much the user moved the mouse (useful to make a mouselook, for example), use the getMouseMotion
function. Reference:
getMouseMotion() -> Vector2