Created
April 19, 2019 22:05
-
-
Save jamezrin/4b2425da73aa55f4a75aa8380d8fbb2d to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
INTERVAL=0.1s | |
BUTTON_CODE=3 | |
TARGET_WINDOW="Minecraft" | |
CLICKS=0 | |
RUNNING=true | |
START_TIMESTAMP="$(date +%s)" | |
trap finish INT | |
function finish() { | |
echo "Quitting..." | |
RUNNING=false | |
} | |
function update_status() { | |
clear | |
UPTIME=$(($(date +%s) - ${START_TIMESTAMP})) | |
echo "Time since launch: ${UPTIME} seconds" | |
echo "Sent ${CLICKS} clicks (${INTERVAL} interval)" | |
echo "Press Ctrl+C to stop" | |
} | |
function check_window() { | |
FOCUSED_WINDOW="$(xdotool getwindowfocus getwindowname)" | |
if [[ $FOCUSED_WINDOW == *"$TARGET_WINDOW"* ]]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
function try_click() { | |
if check_window; then | |
CLICKS=$((${CLICKS} + 1)) | |
xdotool click --window "${TARGET_WINDOW}" ${BUTTON_CODE} | |
fi | |
sleep ${INTERVAL} | |
} | |
while ${RUNNING}; do | |
update_status | |
try_click | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment