I started testing pynput with asyncio, but there is a problem that I can not solve at all. My code:
current = set()
def on_press(key):
if key == keyboard.Key.up:
current.add(key)
print('Y')
if key == keyboard.Key.down:
print('Z')
async def listener():
with keyboard.Listener(on_release=None, on_press=on_press) as listener:
listener.join()
loop = asyncio.get_event_loop()
loop.run_until_complete(listener())
print('x')
Well, from what I understand, even what comes after "loop.run_until_complete (function)" does not depend on the end of the loop, so "print ('x')" should be executed along with the loop, This?
In my example, nothing written after the loop runs until it runs out, what I think is that my problem is here:
async def listener():
with keyboard.Listener(on_release=None, on_press=on_press) as listener:
listener.join()
But I still do not know how to solve it.