keyboard.is_pressed() 在 python 中错误地识别了两个键的组合

keyboard.is_pressed() recognizes combination of two keys wrongly in python

这个示例代码:

while 1:
    if keyboard.is_pressed('ctrl+alt'):
        print('to') 

但是当我按下 alt+ctrl 时,它会打印 to。尝试使用:

while 1:

    if keyboard.is_pressed('ctrl+alt') and not keyboard.is_pressed('alt+ctrl') :
        print('to') 

但是不起作用。 我希望它仅在我按下 ctrl+alt 而不是 alt+ctrl 或任何其他键 时打印 to。如何执行此操作。我猜想编辑源代码(不太熟悉这个,但如果它有效就可以了) 或者更具体地说,我希望它仅在我按住 ctrl 然后按下 alt 的同时仍按住 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

编辑固定:

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)

而不只是让它成为两个 if 语句

if keyboard.is_pressed("ctrl") then
    if keyboard.is_pressed("alt") then
        print("done")
    end
end

(没写在python)

已修复。以下代码适用于最新版本

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)