keyboard.is_pressed() recognizes combination of two keys wrongly in python
This example code:
while 1:
if keyboard.is_pressed('ctrl+alt'):
print('to')
But when I press alt+ctrl
it prints to
. Tried using:
while 1:
if keyboard.is_pressed('ctrl+alt') and not keyboard.is_pressed('alt+ctrl') :
print('to')
But doesn't work.
I want it to print to
only when I press ctrl+alt
and not alt+ctrl
or any other key.How to do this. I would guess editing source code (not too familiar with this but if it works it's ok)
Or more specifically I want it to recognize it only when I hold down ctrl
then press alt
while still holding down ctrl
.
Operating System: windows 7
Python Version: 3.8.8
Keyboard: Logitech k200
IDE: pycharm community edition
Module: keyboard module latest version
Module Link: https://github.com/boppreh/keyboard
Pip Version: Latest
Edit Fixed:
import keyboard
def on_alt(event):
if keyboard.is_pressed('ctrl'):
print('Ctrl + Alt pressed')
keyboard.on_press_key('alt', on_alt)
time.sleep(1e6)
Fixed. The following code workes in the latest version
import keyboard
def on_alt(event):
if keyboard.is_pressed('ctrl'):
print('Ctrl + Alt pressed')
keyboard.on_press_key('alt', on_alt)
time.sleep(1e6)