InputState

Input event states for key and mouse button events.

Overview

InputState is an IntEnum that represents whether an input event is a press or release. These values are passed to input handlers to indicate the type of event. For backwards compatibility, InputState values compare equal to legacy string names.

Quick Reference

def handle_input(key, state):
    if state == mcrfpy.InputState.PRESSED:
        print(f"{key} was pressed")
    elif state == mcrfpy.InputState.RELEASED:
        print(f"{key} was released")

scene.on_key = handle_input

# Legacy string comparison still works
if state == "start":   # Same as InputState.PRESSED
    pass
if state == "end":     # Same as InputState.RELEASED
    pass

Values

Value Legacy String Description
PRESSED "start" Key or button was pressed down
RELEASED "end" Key or button was released

Legacy Compatibility

For backwards compatibility with older McRogueFace code, InputState values compare equal to their legacy string equivalents:

# These are equivalent
mcrfpy.InputState.PRESSED == "start"   # True
mcrfpy.InputState.RELEASED == "end"    # True

# Both styles work in handlers
def on_key(key, state):
    # Modern style
    if state == mcrfpy.InputState.PRESSED:
        pass

    # Legacy style (still supported)
    if state == "start":
        pass