Skip to content

How to receive keyboard events from Unreal viewport in Airsim #3381

Discussion options

You must be logged in to vote

Hi @karnikram, have a look at the keyboard python library. It lets you capture any keypress regardless of window focus (and much more).

Here's a quick sample showing how you could go about doing that:

import keyboard

def key_press(key):
    if key.name == 'x':
        print("X was pressed")
    if key.name == 'c': 
        print("Reset key pressed")
        client.reset() # or maybe even keyboard.send('backspace')        

keyboard.on_release(key_press)

Note: in the code above, you just need to include keyboard.on_release(key_press) once in your code, ie: just add it to the beginning of your code, you don't need to loop over it or anything.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@karnikram
Comment options

Answer selected by karnikram
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants