is_key_pressed#

The is_key_pressed variable stores whether or not a keyboard button is currently being pressed.

Examples#

 1# click on the window to give it focus,
 2# and press the 'b' key.
 3
 4def draw():
 5    if py5.is_key_pressed:
 6        if py5.key in ['b', 'B']:
 7           py5.fill(0)
 8    else:
 9        py5.fill(255)
10
11    py5.rect(25, 25, 50, 50)

Description#

The is_key_pressed variable stores whether or not a keyboard button is currently being pressed. The value is true when any keyboard button is pressed, and false if no button is pressed. The key variable and key_code variables (see the related reference entries) can be used to determine which button has been pressed.

Updated on September 11, 2021 16:51:34pm UTC