InputController Class
The InputController class serves as a gateway for sending game input in the Bluetang framework.
What's in an InputController Instance?
Responsibilities
Exposing basic and convenience keyboard inputs
Exposing basic and convenience mouse inputs
Concepts
Backend
Bluetang provides different backend options for input controllers. They are defined in the InputControllers enum:
InputControllers.PYAUTOGUI
: A backend that leverages the PyAutoGUI Python library. Default for Linux & macOS.InputControllers.NATIVE_WIN32
: A backend that leverages Windows' SendInput DLL function. Default for Windows.
To override your platform's default backend, add an entry to your Game plugins:
Game Focus
Before dispatching inputs, an InputController instance will always make sure the game still has focus to prevent accidental inputs to other applications. If the game loses focus, the desired input will be cancelled.
MouseButton Enum
Whenever a mouse button is expected as an argument in a function, an item from the MouseButton enum should be passed:
MouseButton.LEFT
: The left mouse buttonMouseButton.MIDDLE
: The middle mouse buttonMouseButton.RIGHT
: The right mouse button
If you plan to use mouse input, make sure to import the enum:
from bluetang.input_controller import MouseButton
KeyboardKey Enum
When a keyboard key is expected as an argument in a function, an item from the KeyboardKey enum should be passed. Import it with:
from bluetang.input_controller import KeyboardKey
Keyboard Actions
self.handle_keys
Method Signature handle_keys(self, key_collection)
Compare set(key_collection)
to self.previous_key_collection_set
. Release keys that aren't there anymore and press new keys. Keep other keys pressed. Use this method for more human-like keyboard input.
key_collection: A list of valid keyboard key values that should be pressed.
Last updated