Last active
July 1, 2025 07:15
-
-
Save KtanPatel/317eae0925ba928ed0d80169f6cf8269 to your computer and use it in GitHub Desktop.
[Windows/Mac/Linux] Change screen (Windows screen change [Alt+tab] and tab change [ctrl+tab]), aero key and pageUp + Down Key events for tracking software like upwork, freelancer ...
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/python | |
# eg: python tracker-event-bot.py 50 5 0 | |
# syntax: filename total_sec event_sec shutdown_binary_flag | |
# shutdown_binary_flag => "0 = no", "> 0 = yes & shutdown after that seconds on end of script" | |
import sys | |
from time import sleep | |
import random | |
import ctypes | |
import os | |
import platform | |
try: | |
from pynput.keyboard import Key, Controller | |
except ImportError: | |
print("Please install pynput: pip install pynput") | |
sys.exit(1) | |
keyboard = Controller() | |
IS_WINDOWS = platform.system() == "Windows" | |
IS_MAC = platform.system() == "Darwin" | |
IS_LINUX = platform.system() == "Linux" | |
def press_keys(keys): | |
# Special handling for Alt+Tab | |
if keys[0] == 0x12 and keys[1] == 0x09: | |
if IS_MAC: | |
keyboard.press(Key.cmd) | |
sleep(0.05) | |
keyboard.press(Key.tab) | |
sleep(0.2) | |
keyboard.release(Key.tab) | |
sleep(0.05) | |
keyboard.release(Key.cmd) | |
else: | |
keyboard.press(Key.alt) | |
sleep(0.05) | |
keyboard.press(Key.tab) | |
sleep(0.2) | |
keyboard.release(Key.tab) | |
sleep(0.05) | |
keyboard.release(Key.alt) | |
return | |
# Ctrl+Tab and other combos | |
if keys[0] == 0x11 and keys[1] == 0x09: | |
keyboard.press(Key.ctrl) | |
sleep(0.05) | |
keyboard.press(Key.tab) | |
sleep(0.2) | |
keyboard.release(Key.tab) | |
sleep(0.05) | |
keyboard.release(Key.ctrl) | |
return | |
# For other combos, keep your existing logic | |
if keys[0] in [0x12, 0x11]: | |
if keys[0] == 0x12: | |
keyboard.press(Key.alt if not IS_MAC else Key.cmd) | |
elif keys[0] == 0x11: | |
keyboard.press(Key.ctrl) | |
i = KEYS.index(keys) | |
while i > 0: | |
if keys[1] == 0x09: | |
keyboard.press(Key.tab) | |
sleep(0.2) | |
keyboard.release(Key.tab) | |
sleep(0.2) | |
i -= 1 | |
if keys[0] == 0x12: | |
keyboard.release(Key.alt if not IS_MAC else Key.cmd) | |
elif keys[0] == 0x11: | |
keyboard.release(Key.ctrl) | |
else: | |
for k in keys: | |
if k == 0x25: | |
keyboard.press(Key.left) | |
elif k == 0x26: | |
keyboard.press(Key.up) | |
elif k == 0x21: | |
keyboard.press(Key.page_up) | |
elif k == 0x28: | |
keyboard.press(Key.down) | |
elif k == 0x27: | |
keyboard.press(Key.right) | |
elif k == 0x22: | |
keyboard.press(Key.page_down) | |
sleep(0.2) | |
for k in reversed(keys): | |
if k == 0x25: | |
keyboard.release(Key.left) | |
elif k == 0x26: | |
keyboard.release(Key.up) | |
elif k == 0x21: | |
keyboard.release(Key.page_up) | |
elif k == 0x28: | |
keyboard.release(Key.down) | |
elif k == 0x27: | |
keyboard.release(Key.right) | |
elif k == 0x22: | |
keyboard.release(Key.page_down) | |
TOTAL_TIME = 60 | |
SLEEP_TIME = 5 | |
START_TIME = 0 | |
ALLOW_SHUTDOWN = 0 | |
if len(sys.argv) == 4: | |
TOTAL_TIME = float(sys.argv[1]) | |
SLEEP_TIME = float(sys.argv[2]) | |
ALLOW_SHUTDOWN = int(sys.argv[3]) | |
elif len(sys.argv) == 3: | |
TOTAL_TIME = float(sys.argv[1]) | |
SLEEP_TIME = float(sys.argv[2]) | |
elif len(sys.argv) == 2: | |
TOTAL_TIME = float(sys.argv[1]) | |
else: | |
print('Something Wrong. Syntax Error: expect => :filename.py Total_time_sec event_time_sec shutdown_binary_flag') | |
sys.exit(0) | |
KEYS = [[0x12, 0x09], [0x12, 0x09], [0x12, 0x09], [0x11, 0x09], [0x11, 0x09], [0x11, 0x09], [0x25, 0x26], [0x25, 0x26], [0x25, 0x26], [0x25, 0x26], [0x25, 0x26], [0x25, 0x26], [ | |
0x21, 0x28], [0x27, 0x22]] # Alt+tab Ctrl+tab Left+Up pgUp+Down Up+PgDown | |
while True: | |
if START_TIME > TOTAL_TIME: | |
if ALLOW_SHUTDOWN > 0: | |
if IS_WINDOWS: | |
os.system("shutdown /s /t " + str(ALLOW_SHUTDOWN)) | |
elif IS_LINUX: | |
os.system("shutdown -h +" + str(ALLOW_SHUTDOWN)) | |
elif IS_MAC: | |
os.system("sudo shutdown -h +" + str(ALLOW_SHUTDOWN)) | |
break | |
else: | |
break | |
index = random.randint(0, len(KEYS) - 1) | |
press_keys(KEYS[index]) | |
sleep(SLEEP_TIME) | |
if IS_WINDOWS: | |
os.system('cls') | |
else: | |
os.system('clear') | |
print('Time Spent: ==>', START_TIME) | |
print('Time Remaining: ==>', TOTAL_TIME - START_TIME) | |
print() | |
START_TIME += SLEEP_TIME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment