Skip to content

Commit

Permalink
Updated wakey to v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerrington committed Dec 31, 2020
1 parent 75923ee commit a7eb24e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
Binary file modified README.md
Binary file not shown.
Binary file added imgs/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/verbose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 69 additions & 14 deletions wakey.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
import keyboard, time, sys
import os, logging
import ctypes
import os

if sys.platform == "win32":
cmd = 'mode 30,10'
os.system(cmd)
ctypes.windll.kernel32.SetConsoleTitleW('Wakey')
def main(duration, frequency, verbose, log):

if log:
# Setup logging
file, ext = os.path.splitext(__file__)
logfile = file+'.log'
logging.basicConfig(filename=logfile, filemode='w', format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO, datefmt='%b-%d-%y %H:%M:%S')

print("Keeping computer awake :)")
if sys.platform == "win32":
#cmd = 'mode 30,10'
#os.system(cmd)
ctypes.windll.kernel32.SetConsoleTitleW('Wakey')
keypress = 'f15'

while True:
try:
keyboard.press_and_release('f15')
delay = 300 # 5 minutes
time.sleep(delay) # Sleep for the amount of seconds generated
except KeyboardInterrupt:
# quit
sys.exit()
if sys.platform == 'linux':
if os.getuid() != 0:
print("Wakey needs to run as root/sudo. Please try relaunch")
sys.exit()
else:
keypress = 'shift'


# time.sleep() is in seconds. Multiple minutes wanted by 60 seconds to get delay
delay = frequency * 60
print("Keeping computer awake :)")
if verbose:
print(f'Pressing {keypress} every {delay} seconds')

while True:
try:
if sys.platform == "win32":
keyboard.press_and_release(keypress)
if verbose:
print(f'Button {keypress} was pressed at {currenttime()}')

if log:
logging.info(f'Button {keypress} was pressed at {currenttime()}')

if sys.platform == "linux":
keyboard.press_and_release(keypress)

time.sleep(delay) # Sleep for the amount of seconds generated
except KeyboardInterrupt:
# quit
sys.exit()


def currenttime():
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
return current_time



# If we are running the file directly, lets add some arguments for our script.
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Simply keep your computer awake and session active")
parser.add_argument("-d", "--duration", type=int, help="Length of time in minutes, default is forever")
parser.add_argument("-f", "--frequency", type=int, help="Frequency of keypress in minutes, default is 1 minute", default=1)
parser.add_argument("-v", "--verbose", action='store_true', help="Verbosely see the output in the console")
parser.add_argument("-l", "--log", action='store_true', help="Creates a log of the application for later reference")

# gather arguments
args = parser.parse_args()
duration = args.duration
frequency = args.frequency
verbose = args.verbose
log = args.log

main(duration, frequency, verbose, log)

0 comments on commit a7eb24e

Please sign in to comment.