Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.