Python Forum

Full Version: Solve Pynput Problem when changing language?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,
I am working on a project in PYTHON and I want to create a keylogger for 2 languages english and greek.
For this I have created the below code.

    from pynput.keyboard import Key, Listener
    from langdetect import detect
    from pynput import keyboard
    def on_press(key):
        global string
        if key == keyboard.Key.esc: #if button escape is pressed close the program
            listener.stop()
        elif key == keyboard.Key.space:
            print(string)
            string=""
        else:
            string = ''.join([string,str(key).replace("'","")])
    string=""
    controller = keyboard.Controller()
    # Collect events until released
    listener = keyboard.Listener(on_press=on_press)
    listener.start()
I run it and all good until I change the language.
The problem that I am facing is explained below.
If I start typing in english, the printed result is in english but when I change in greek the printed result remains english.
If I start typing in greek the printed result is in greek, but when I change in english the result remains greek.
[Image: qC9GK8x]
[Image: Z6Y0Lzp]
How can I solve this problem in order to take the same language result after an input language change?
Any help or advice would be great!
Thanks in advance.