Last active
October 23, 2016 21:20
-
-
Save triple-j/68e66f1565cda3720d6928ec521176a6 to your computer and use it in GitHub Desktop.
Automatic Mouse Clicker
This file contains hidden or 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 | |
# Automatic Mouse Clicker | |
# For use with the game [**Crush Crush**](http://store.steampowered.com/app/459820/) | |
# Hold down CTRL+SHIFT to save mouse position | |
# Hold down ALT to move mouse and rapidly send a mouse click events | |
# (Linux Only: requires programs `xinput` and `xdotool`) | |
import re | |
import subprocess | |
from threading import Thread | |
def processInput(): | |
global DEBUG | |
global alt_pressed | |
global ctrl_pressed | |
global shift_pressed | |
global xinput_command | |
process = subprocess.Popen(xinput_command, stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT, shell=True) | |
for line in iter(process.stdout.readline, ''): | |
line = line.strip() | |
if DEBUG is True: | |
print(line) | |
if line.strip() == b'key press 64' or line.strip() == b'key press 108': | |
print(" == ALT pressed ==") | |
alt_pressed = True | |
if line.strip() == b'key release 64' or line.strip() == b'key release 108': | |
print(" == ALT released ==") | |
alt_pressed = False | |
if line.strip() == b'key press 37' or line.strip() == b'key press 105': | |
print(" == CTRL pressed ==") | |
ctrl_pressed = True | |
if line.strip() == b'key release 37' or line.strip() == b'key release 105': | |
print(" == CTRL released ==") | |
ctrl_pressed = False | |
if line.strip() == b'key press 50' or line.strip() == b'key press 62': | |
print(" == SHIFT pressed ==") | |
shift_pressed = True | |
if line.strip() == b'key release 50' or line.strip() == b'key release 62': | |
print(" == SHIFT released ==") | |
shift_pressed = False | |
if __name__ == "__main__": | |
keyboard_id = 8 | |
DEBUG = False | |
alt_pressed = False | |
ctrl_pressed = False | |
shift_pressed = False | |
mouse_x = None | |
mouse_y = None | |
xinput_command = "xinput test {}".format(keyboard_id) | |
getmouselocation_command = "xdotool getmouselocation" | |
setmouselocation_command = "xdotool mousemove {} {}" | |
mouseclick_command = "xdotool click 1" | |
processInputThread = Thread(target = processInput) | |
processInputThread.setDaemon(True) | |
processInputThread.start() | |
while True: | |
try: | |
if alt_pressed is True: | |
if mouse_x is not None and mouse_y is not None: | |
subprocess.check_call(setmouselocation_command.format(mouse_x, mouse_y), shell=True) | |
subprocess.check_call(mouseclick_command, shell=True) | |
if DEBUG is True: | |
print("Auto Click") | |
else: | |
if DEBUG is True: | |
print("Mouse Location Not Set") | |
if ctrl_pressed is True and shift_pressed is True: | |
getmouselocation_output = subprocess.check_output(getmouselocation_command, shell=True) | |
getmouselocation_regex = re.compile(b'x:(\d+) y:(\d+)', re.IGNORECASE) | |
getmouselocation_match = re.search(getmouselocation_regex, getmouselocation_output) | |
if getmouselocation_match is not None: | |
mouse_x = int(getmouselocation_match.group(1)) | |
mouse_y = int(getmouselocation_match.group(2)) | |
if DEBUG is True: | |
print("Set Mouse Position (x:{} y:{})".format(mouse_x, mouse_y)) | |
except (KeyboardInterrupt, SystemExit): | |
print("\nStop Program") | |
break | |
This file contains hidden or 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
#!/bin/bash | |
TIME="1 day" | |
SLEEP="30" | |
if [ -n "$1" ]; then | |
TIME="$1" | |
fi | |
if [ -n "$2" ]; then | |
SLEEP="$2" | |
fi | |
FORWARDS="+$TIME" | |
BACKWARDS="-$TIME" | |
sudo bash -c "date -s \"$FORWARDS\"; sleep $SLEEP; date -s \"$BACKWARDS\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment