Next: , Previous: , Up: Top   [Contents][Index]


4 Module inp

This chapter describes the contents of the inp module in detail.

4.1 nothing

This function does — just like the name says — nothing. It takes a arbitrary count of positional and keyword arguments and returns None.

4.2 InputHandler

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.

4.2.1 methods

Here are all methods of the InputHandler

4.2.1.1 __init__/constructor

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!

4.2.1.2 get_input

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.

4.2.2 attributes

Here are all important attributes of the InputHandler listed.

4.2.2.1 screen

This variable holds the screen to get input from. It is None until the InputHandler is registered on a game.

4.2.2.2 blocking

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.

4.3 PassiveInput

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.

4.3.1 methods

Here are all the methods of PassiveInput

4.3.1.1 get_input

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.

4.3.1.2 get_key

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.

4.4 key-constants

This module imports all the key-constants from curses. Please look at the python-curses documentation for their meaning.


Next: , Previous: , Up: Top   [Contents][Index]