Console::Input

console 0.2.0 · app/console/input.rb · 243 lines · view source

Console::Input -- one action vocabulary across keyboard, controller and pointer.

A cart asks input.pressed?(:accept) and never has to care whether the player is on a keyboard, a gamepad, or a touchscreen. The snapshot is taken once at the top of the frame (see Input#snapshot) so repeated queries during a frame are cheap and consistent.

def initialize(args)
line 21
def new_action
line 32
def refresh

Recompute the frame snapshot. Called once per tick by Console#tick.

def enable_text

Start collecting typed characters. Required before typed returns anything; on touch devices this raises the on-screen keyboard.

def disable_text
line 91

queries

def held?(action)
line 98
def pressed?(action)
line 103
def released?(action)
line 108
def any_pressed?(*list)
line 113
def axis_x

-1.0 .. 1.0, analog when available.

def axis_y
line 123
def axis_vector
line 127
def last_device
line 131
def controller_connected?
line 135

pointer

def pointer

A single pointer abstraction covering mouse and first touch point. x/y are in screen space, already offset by the console camera.

def pointer_down?
line 147
def pointer_pressed?
line 151
def pointer_released?
line 155
def pointer_inside?(r)
line 159
def clicked?(r)

True on the frame the pointer went down inside r.

text

def typed

Characters typed since the last frame (requires DR.start_text_input).

def text_entered?(ch = nil)
line 175
def set(action, held, pressed = nil)
line 183
def switch_pro?

A Nintendo Switch Pro Controller relabels a/b, so the confirm button is physically b on that pad and a everywhere else.

def c_accept_button
line 203
def c_cancel_button
line 207
def pad_held?(button)

Dynamic key lookups raise for buttons a given pad does not expose, and a disconnected pad has no keys at all. Both are normal, not errors.

def pad_down?(button)
line 219
def refresh_pointer
line 225