Py5KeyEvent.get_key_code()

Py5KeyEvent.get_key_code()

Return the key code 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    msgs = []
12    if e.get_key() == py5.CODED:
13        key_code = e.get_key_code()
14        if key_code == py5.UP:
15            py5.println('UP')
16        if key_code == py5.LEFT:
17            py5.println('LEFT')
18        if key_code == py5.RIGHT:
19            py5.println('RIGHT')
20        if key_code == py5.DOWN:
21            py5.println('DOWN')

Description

Return the key code for the key event. This method is important for key events involving coded keys such as the arrow or modifier keys. This information can also be obtained with key_code.

Underlying Processing method: getKeyCode

Syntax

get_key_code() -> int

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