I've been playing around with the Minecraft Python API and I'd like to run some of my code in response to a keypress within the game. I'm able to selectively run code based on player position or block hit events, but I'd like to bind code to a particular keypress.

  • As far as I understand you want to capture a keypress from a regular (USB)keyboard and you are asking how to code this in python. I cannot see where it is specific to Raspberry Pi. Where is the problem with the RasPi?
    – Ingo
    Commented Mar 3, 2019 at 14:00

1 Answer 1


You could try importing keyboard and using code a bit like this:

import keyboard

while True:
        if keyboard.is_pressed('e'):
            print('E hotkey pressed')

Bear in mind that you have to install keyboard using pip3 install keyboard.

This module requires administrative privileges and thus must run under sudo python3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.