Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

Python
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()


What I have tried:

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.
<a href="https://ibb.co/qC9GK8x"></a>
<a href="https://ibb.co/Z6Y0Lzp"></a>

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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900