Py5KeyEvent.get_key()

Py5KeyEvent.get_key()

Return the key for the key event.

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    pressed_key = e.get_key()
12    if pressed_key != py5.CODED:
13        py5.println(f'the {pressed_key} key was pressed')

Description

Return the key for the key event. If the value is CODED, use Py5KeyEvent.get_key_code() instead. This information can also be obtained with key.

Underlying Processing method: getKey

Syntax

get_key() -> chr

Updated on April 27, 2022 11:05:24am UTC