Py5KeyEvent.get_modifiers()

Py5KeyEvent.get_modifiers()

Integer value used to identify which modifier keys (if any) are currently pressed.

Examples

 1def setup():
 2    py5.size(200, 200, py5.P2D)
 3    py5.rect_mode(py5.CENTER)
 4
 5
 6def draw():
 7    py5.square(py5.random(py5.width), py5.random(py5.height), 10)
 8
 9
10def key_pressed(e):
11    modifiers = e.get_modifiers()
12    msgs = []
13    if modifiers & e.SHIFT:
14        msgs.append('shift is down')
15    if modifiers & e.CTRL:
16        msgs.append('control is down')
17    if modifiers & e.META:
18        msgs.append('meta is down')
19    if modifiers & e.ALT:
20        msgs.append('alt is down')
21    py5.println('key pressed: ' + (', '.join(msgs) if msgs else 'no modifiers'))

Description

Integer value used to identify which modifier keys (if any) are currently pressed. Information about the modifier keys is encoded in the integer value and can be parsed with bit masking, as shown in the example.

Underlying Processing method: getModifiers

Syntax

get_modifiers() -> int

Updated on April 27, 2022 10:44:51am UTC