Hi everyone,
I am working on a project (just started) in PYTHON and I want to create a keylogger for 2 languages english and greek. For this I have created the below (it is under "construction") 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. (please see the screenshots+explanations).

1.png

2.png

In the first picture I started typing in english and the printed result was in english but when I changed in greek the printed result remained english.
In the second picture I started in greek and the printed result was in greek, but when I change in english the result remains greek.

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.

Recommended Answers

This is strictly a guess. I'd want to see what langdetect is doing. Also read and try implementing the code on the URL to follow after the text:
"To enforce consistent results, call following code before the first language detection:"

Jump to Post

All 3 Replies

This is strictly a guess. I'd want to see what langdetect is doing. Also read and try implementing the code on the URL to follow after the text:
"To enforce consistent results, call following code before the first language detection:"
https://pypi.org/project/langdetect/

Thanks for the feedback a lot.
I think that the problem is not in the langdetect and I think that there is a problem with the listener.
I tried stopping the active listener when language is changed and starting a new one but nothing got fixed.
I thought that starting a new listener would change the result and make it equivalent to the input languge ( :( didn;t work).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.