LogoLogo
  • 🐟An Introduction to Bluetang
  • Features
    • 📔Overview
  • Deepseek Integration
    • 😃What are the benefits?
  • How To Use
    • â„šī¸Important Information
    • 🔗Important Links
    • 📖Wiki
      • 💾Installation
        • đŸ’ŋLinux
        • đŸĒŸWindows
      • 🔃Update
      • đŸ’ģBluetang CLI Tool
      • 👨‍đŸ’ģClasses
        • GameAgent Class
        • Game Class
        • GameFrame Class
        • InputController Class
      • 🔌Plugins
        • GameAgent Plugin
        • Game Plugin
        • Training a Context Classifier
  • 📑Whitepaper
Powered by GitBook
On this page
  1. How To Use
  2. Wiki
  3. Classes

InputController Class

PreviousGameFrame ClassNextPlugins

Last updated 4 months ago

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 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:

class BluetangNuclearThroneGame(Game, metaclass=Singleton):

    def __init__(self, **kwargs):
        kwargs["platform"] = "steam"

        kwargs["input_controller"] = InputControllers.PYAUTOGUI  # <= Specify your InputController backend here 

        kwargs["window_name"] = "Nuclear Throne"

        kwargs["app_id"] = "242680"
        kwargs["app_args"] = None

        super().__init__(**kwargs)

        self.api_class = NuclearThroneAPI
        self.api_instance = None

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 button

  • MouseButton.MIDDLE: The middle mouse button

  • MouseButton.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.

📖
👨‍đŸ’ģ
PyAutoGUI