[Python] keyboard module doesn't detect language switch in real time [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a keylogger project and encountered an issue: The keyboard module detects the current language when the program is running and saves it, but when the user changes the language on the system, the program keeps saving the keys based on the first language pressed, instead of updating to the current language.

    Example:

    When I start with English and press 'a', it prints 'a'. When I switch to Hebrew and press 'ש', it still prints 'a' instead of 'ש'. When I start with Hebrew and press 'ש', it prints 'ש'. When I switch back to English and press 'a', it still prints 'ש' instead of 'a'. What I've tried:

    I've checked if the keyboard module has a built-in way to detect and update language in real-time, but I couldn't find a solution.

    I tried to rerun the keyboard module for every key press, but that didn't work.

    I was suggested to create a manual mapping for languages and convert the keys myself, but that approach isn't scalable for all languages.

    Code used:

    import keyboard

    def on_press(key_event):
    print(key_event.name)

    keyboard.on_press(on_press)
    keyboard.wait()


    Question: How can I make sure that the key press is mapped to the correct key based on the current language of the system in real time?

    Continue reading...

Compartilhe esta Página