Check if two keys were pressed at the same time python

Asked

Viewed 18 times

0

Hello guys I’m using python and the pynput.Keyboard module to check keystrokes until then everything ok, but I would like to know when two keys were pressed at the same time: example Shift+L or any other combination.

the current code is:

from pynput.keyboard import Listener, Key

def press(key):
  print(key)

with Listener(on_press=press, on_release=release, on_pressed=pressed) as listener:
  listener.join()

1 answer

0

You would have to have a list, outside the "press" and "release" functions. When a keydown is registered by "press", add it to the list (if it’s not already there). When a keyup is registered by "release", remove it from the list.

Then, in the epilogue of the function "press", check if any key combination is present in the list.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.