Next: Module character, Previous: Module map, Up: Top [Contents][Index]
This chapter describes the contents of the inp module in detail.
This function does — just like the name says — nothing. It takes a arbitrary count of positional and keyword arguments and returns None.
The InputHandler waits for input and handles it as it arrives. It also controls wether the game runs in real-time or in turn-based mode. This might seem a little bit messed up at first. But it makes (a little bit) sense if you see that the difference between turn-based and real-time games only is wether you take input in blocking mode or not.
Here are all methods of the InputHandler
The InputHandler takes at instanciation one argument. A float, int or bool that indicates wether the game should run in real-time or in turn-based mode. If it’s evaluates to False (e.g. it’s 0 or False), otherwise the given number is waited between the frames (in seconds). This means that you can’t pass True!
This method waits for input and processes it. Processing means that the input-event that was catched is lokked up in InputHandler.callbacks and calls the function returned by the lookup, with the input-event as first and only argument.
Here are all important attributes of the InputHandler listed.
This variable holds the screen to get input from. It is None until the InputHandler is registered on a game.
This variable says wether input should be get in blocking or non blocking mode. See time-mode, for more on that. You can change this at runtime. This will take effect on the opened window imediately.
The PassiveInput
class is a alternative InputHandler
.
Instead of catching the input every frame, the PassiveInput
provides the method get_key
which returns the last pressed key.
PassiveInput inherits from InputHandler.
Here are all the methods of PassiveInput
This method is called in the same situations as the InputHandler.get_input. But this version doesn’t do or return anything because the input is requested manually by the programmer.
This method is just some kind of link to curses.screen.getch(). It returns the last pressed key and returns -1 if no key was pressed and blocking is True.
This module imports all the key-constants from curses. Please look at the python-curses documentation for their meaning.
Next: Module character, Previous: Module map, Up: Top [Contents][Index]