Avatar ·

Python: How to block the keys for everything except the Keyboard module?

📁 Advanced Python Topics, question, bots, AI

I have a program that should substitute certain characters and combinations of symbols when pressing certain keys:


import keyboard
while True:
    hotkey = keyboard.read_hotkey(suppress=False)
    if hotkey == 'j+k':
        keyboard.write('j+k')

(I do not use keyboard.add_hotkey(), because in the future the plans are not specific hot keys, but checking for certain keys in hotkey. J + K, say, in a text editor, 'J+K' will be printed. But I get 'jkj+k'. That is, the keys themselves j