0

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 Mar 3 at 14:00
0

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

import keyboard
while True:
    try:
        if keyboard.is_pressed('e')
            print('E hotkey pressed')
            break
        else:
            pass
    except:
        break



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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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