brickPi+ Python Keyboard Input Question

BrickPi/ at master · DexterInd/BrickPi · GitHub

Hello. I am following the robotic arm example and its working but I cant figure out how to make the robot arm move in tiny increments on each key press instead of moving indefinitely until another key is pressed per the example code.

Hope this makes sense. It currently moves until another key is pressed to stop it. I want to code it so it stops moving on key up. what do I change in the python example code to achieve this? Thank you


Please give a link to the example so we can have a look

1 Like

Hello. The link is at the top of my post.

BrickPi/ at master · DexterInd/BrickPi · GitHub


Seems like this is tougher than expected.

Is a module which appears to offer key press and key release, but you will have to figure out exactly which example will work for you

from pynput import keyboard

def on_press(key):
        print('alphanumeric key {0} pressed'.format(
    except AttributeError:
        print('special key {0} pressed'.format(

def on_release(key):
    print('{0} released'.format(
    if key == keyboard.Key.esc:
        # Stop listener
        return False

# Collect events until released
with keyboard.Listener(
        on_release=on_release) as listener:

# ...or, in a non-blocking fashion:
listener = keyboard.Listener(

1 Like

I am not an expert at Python.

In the past, when using other languages, key press usually means press-and-release.

To detect the actual push of a key, the action I have had to use was the event key_down, and the key_up event detects when the key is released.

  • Note that the equivalent mouse events are [left|right] button_pressed and the corresponding button_down and button_up events.

This may be modified by other things that determine if the key will repeat if held down.  (i.e.  Will the key send repeated key_down messages or not.)

Additional research will be needed as detecting key motion as opposed to key presses is not trivial.