Created
December 4, 2016 13:21
-
-
Save teknikqa/57bce781d95dc2cee038d61ae2dacd3e to your computer and use it in GitHub Desktop.
Script that randomly presses 'w', 'a', 's' or 'd' every once in a while and kills itself when another key is pressed.
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
#!/usr/bin/env python3 | |
import datetime | |
import random | |
import subprocess | |
import sys | |
import time | |
import threading | |
import keylogger | |
WASD = ['w', 'a', 's', 'd'] | |
def random_time(minimum=30, maximum=60): | |
return random.randint(minimum, maximum) | |
def press_key(key='w'): | |
subprocess.call(['xdotool', 'key', key]) | |
class KeyPressThread(threading.Thread): | |
def run(self): | |
while True: | |
time.sleep(random_time()) | |
key = random.choice(WASD) | |
press_key(key) | |
print('{}: pressed {}'.format(datetime.datetime.now(), key)) | |
def exit_if_user(_0, _1, key): | |
if key is None: | |
return | |
if key not in WASD: | |
print('exiting with {}'.format(key)) | |
sys.exit() | |
def main(): | |
key_thread = KeyPressThread() | |
key_thread.daemon = True | |
key_thread.start() | |
time.sleep(5) | |
print('starting logger') | |
while True: | |
keylogger.log(lambda: False, exit_if_user) | |
print('this should not happen') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment