libretro.api.input.keyboard

Keyboard key codes, modifier flags, and input types.

Module Attributes

retro_key

Corresponds to retro_key in libretro.h.

retro_keyboard_event_t

Notify the core of a single keyboard event.

Classes

Key

Enumeration of keyboard key codes.

KeyModifier

Flags for key modifiers.

KeyboardState

Snapshot of the keyboard state.

retro_keyboard_callback

Function registered by a core to receive keyboard events.

class Key[source]

Bases: IntEnum

Enumeration of keyboard key codes.

Corresponds to the RETROK_* constants in libretro.h.

>>> from libretro.api.input import Key
>>> Key.A
<Key.A: 97>
UNKNOWN = 0
BACKSPACE = 8
TAB = 9
CLEAR = 12
RETURN = 13
PAUSE = 19
ESCAPE = 27
SPACE = 32
EXCLAIM = 33
QUOTEDBL = 34
HASH = 35
DOLLAR = 36
AMPERSAND = 38
QUOTE = 39
LEFTPAREN = 40
RIGHTPAREN = 41
ASTERISK = 42
PLUS = 43
COMMA = 44
MINUS = 45
PERIOD = 46
SLASH = 47
Zero = 48
One = 49
Two = 50
Three = 51
Four = 52
Five = 53
Six = 54
Seven = 55
Eight = 56
Nine = 57
COLON = 58
SEMICOLON = 59
LESS = 60
EQUALS = 61
GREATER = 62
QUESTION = 63
AT = 64
LEFTBRACKET = 91
BACKSLASH = 92
RIGHTBRACKET = 93
CARET = 94
UNDERSCORE = 95
BACKQUOTE = 96
A = 97
B = 98
C = 99
D = 100
E = 101
F = 102
G = 103
H = 104
I = 105
J = 106
K = 107
L = 108
M = 109
N = 110
O = 111
P = 112
Q = 113
R = 114
S = 115
T = 116
U = 117
V = 118
W = 119
X = 120
Y = 121
Z = 122
LEFTBRACE = 123
BAR = 124
RIGHTBRACE = 125
TILDE = 126
DELETE = 127
KP0 = 256
KP1 = 257
KP2 = 258
KP3 = 259
KP4 = 260
KP5 = 261
KP6 = 262
KP7 = 263
KP8 = 264
KP9 = 265
KP_PERIOD = 266
KP_DIVIDE = 267
KP_MULTIPLY = 268
KP_MINUS = 269
KP_PLUS = 270
KP_ENTER = 271
KP_EQUALS = 272
UP = 273
DOWN = 274
RIGHT = 275
LEFT = 276
INSERT = 277
HOME = 278
END = 279
PAGEUP = 280
PAGEDOWN = 281
F1 = 282
F2 = 283
F3 = 284
F4 = 285
F5 = 286
F6 = 287
F7 = 288
F8 = 289
F9 = 290
F10 = 291
F11 = 292
F12 = 293
F13 = 294
F14 = 295
F15 = 296
NUMLOCK = 300
CAPSLOCK = 301
SCROLLOCK = 302
RSHIFT = 303
LSHIFT = 304
RCTRL = 305
LCTRL = 306
RALT = 307
LALT = 308
RMETA = 309
LMETA = 310
LSUPER = 311
RSUPER = 312
MODE = 313
COMPOSE = 314
HELP = 315
PRINT = 316
SYSREQ = 317
BREAK = 318
MENU = 319
POWER = 320
EURO = 321
UNDO = 322
OEM_102 = 323
BROWSER_BACK = 324
BROWSER_FORWARD = 325
BROWSER_REFRESH = 326
BROWSER_STOP = 327
BROWSER_FAVORITES = 329
BROWSER_HOME = 330
VOLUME_MUTE = 331
VOLUME_DOWN = 332
VOLUME_UP = 333
MEDIA_NEXT = 334
MEDIA_PREV = 335
MEDIA_STOP = 336
MEDIA_PLAY_PAUSE = 337
LAUNCH_MAIL = 338
LAUNCH_MEDIA = 339
LAUNCH_APP1 = 340
LAUNCH_APP2 = 341
property is_modifier
Returns:

True if this key represents one of the modifiers defined in KeyModifier.

__new__(value)
classmethod value in self

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members. 3) value is a pseudo-member (flags)

classmethod self[name]

Return the member matching name.

__init__()
classmethod iter(self)

Return members in definition order.

classmethod len(self)

Return the number of members (no aliases)

class KeyModifier[source]

Bases: IntFlag

Flags for key modifiers.

Corresponds to the RETROKMOD_* constants in libretro.h.

>>> from libretro.api.input import KeyModifier
>>> KeyModifier.SHIFT
<KeyModifier.SHIFT: 1>
NONE = 0
SHIFT = 1
CTRL = 2
ALT = 4
META = 8
NUMLOCK = 16
CAPSLOCK = 32
SCROLLOCK = 64
__new__(value)
other in self

Returns True if self has at least the same flags set as other.

iter(self)

Returns flags in definition order.

len(self)

Return the number of members (no aliases)

classmethod self[name]

Return the member matching name.

__init__()
class KeyboardState[source]

Bases: InputDeviceState

Snapshot of the keyboard state.

Each field corresponds to a key’s pressed state.

>>> from libretro.api.input import KeyboardState
>>> state = KeyboardState()
>>> state.space
False
backspace
tab
clear
return_key
pause
escape
space
exclaim
quotedbl
hash
dollar
ampersand
quote
leftparen
rightparen
asterisk
plus
comma
minus
period
slash
zero
one
two
three
four
five
six
seven
eight
nine
colon
semicolon
less
equals
greater
question
at
leftbracket
backslash
rightbracket
caret
underscore
backquote
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
leftbrace
bar
rightbrace
tilde
delete
kp0
kp1
kp2
kp3
kp4
kp5
kp6
kp7
kp8
kp9
kp_period
kp_divide
kp_multiply
kp_minus
kp_plus
kp_enter
kp_equals
up
down
right
left
insert
home
end
pageup
pagedown
f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
numlock
capslock
scrolllock
rshift
lshift
rctrl
lctrl
ralt
lalt
rmeta
lmeta
lsuper
rsuper
mode
compose
help
print
sysreq
break_key
menu
power
euro
oem_102
browser_back
browser_forward
browser_refresh
browser_stop
browser_favorites
browser_home
volume_mute
volume_down
volume_up
media_next
media_prev
media_stop
media_play_pause
launch_mail
launch_media
launch_app1
launch_app2
self[item][source]

Get the pressed state of the given key.

Parameters:

item (int | Key) – A Key or an equivalent key code.

Return type:

bool

Returns:

True if the given Key or key code is currently pressed.

Raises:

KeyError – If item isn’t a valid key code.

>>> from libretro.api.input import KeyboardState, Key
>>> state = KeyboardState(a=True)
>>> state[Key.A]
True
>>> state[Key.B]
False
__init__(backspace=False, tab=False, clear=False, return_key=False, pause=False, escape=False, space=False, exclaim=False, quotedbl=False, hash=False, dollar=False, ampersand=False, quote=False, leftparen=False, rightparen=False, asterisk=False, plus=False, comma=False, minus=False, period=False, slash=False, zero=False, one=False, two=False, three=False, four=False, five=False, six=False, seven=False, eight=False, nine=False, colon=False, semicolon=False, less=False, equals=False, greater=False, question=False, at=False, leftbracket=False, backslash=False, rightbracket=False, caret=False, underscore=False, backquote=False, a=False, b=False, c=False, d=False, e=False, f=False, g=False, h=False, i=False, j=False, k=False, l=False, m=False, n=False, o=False, p=False, q=False, r=False, s=False, t=False, u=False, v=False, w=False, x=False, y=False, z=False, leftbrace=False, bar=False, rightbrace=False, tilde=False, delete=False, kp0=False, kp1=False, kp2=False, kp3=False, kp4=False, kp5=False, kp6=False, kp7=False, kp8=False, kp9=False, kp_period=False, kp_divide=False, kp_multiply=False, kp_minus=False, kp_plus=False, kp_enter=False, kp_equals=False, up=False, down=False, right=False, left=False, insert=False, home=False, end=False, pageup=False, pagedown=False, f1=False, f2=False, f3=False, f4=False, f5=False, f6=False, f7=False, f8=False, f9=False, f10=False, f11=False, f12=False, f13=False, f14=False, f15=False, numlock=False, capslock=False, scrolllock=False, rshift=False, lshift=False, rctrl=False, lctrl=False, ralt=False, lalt=False, rmeta=False, lmeta=False, lsuper=False, rsuper=False, mode=False, compose=False, help=False, print=False, sysreq=False, break_key=False, menu=False, power=False, euro=False, oem_102=False, browser_back=False, browser_forward=False, browser_refresh=False, browser_stop=False, browser_search=False, browser_favorites=False, browser_home=False, volume_mute=False, volume_down=False, volume_up=False, media_next=False, media_prev=False, media_stop=False, media_play_pause=False, launch_mail=False, launch_media=False, launch_app1=False, launch_app2=False)
classmethod __new__(*args, **kwargs)
retro_keyboard_event_t

Notify the core of a single keyboard event.

Registered by the core and called by the frontend when a key is pressed, released, or generates a text character. The keycode and character may be reported independently (e.g. a single keypress can yield multiple text characters, or a character can arrive without a corresponding keycode).

Parameters:
  • downTrue if the key is being pressed, False if it is being released.

  • keycode – The Key of the key involved, or Key.UNKNOWN if only a character event is being reported.

  • character – A UTF-32 codepoint generated by this event, or 0 if no character was generated.

  • key_modifiers – A bitmask of KeyModifier flags that were active when the event occurred.

Corresponds to retro_keyboard_event_t in libretro.h.

See also

InputDriver.keyboard_event()

The suggested entry point for this registered callback in libretro.py.

class retro_keyboard_callback[source]

Bases: Structure

Function registered by a core to receive keyboard events. Can be invoked directly as a callable.

Corresponds to retro_keyboard_callback in libretro.h.

callback
__deepcopy__(_)[source]

Return a copy of this object. Intended for use with copy.deepcopy().

self(pressed, keycode, character, key_modifiers)[source]

Invoke the keyboard event callback. Does nothing if callback is None.

Parameters:
  • pressed (bool) – Whether the key was pressed or released.

  • keycode (Key) – The Key code.

  • character (int | str | bytes) – A single character as a UTF-32 codepoint or a single-character str or bytes object.

  • key_modifiers (KeyModifier) – Active KeyModifier flags.

Return type:

None

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
retro_key

Corresponds to retro_key in libretro.h.

retro_mod

alias of c_int