How to receive keyboard events from Unreal viewport in Airsim #3381
-
Hi, Is there a way to receive a key press event in the Unreal viewport, using the Python API? There is currently a I need this because I've configured my Unreal environment to reset upon a key press, for which the focus has to be on the viewport. Upon this reset I want Airsim also to be reset. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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. |
Beta Was this translation helpful? Give feedback.
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:
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.