Created
August 5, 2020 04:36
-
-
Save Trumeet/97393f2d4c52450b2ea3ac2ab95c7892 to your computer and use it in GitHub Desktop.
MC Auto key tool
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 | |
export MOUSE_LEFT=1 | |
export MOUSE_RIGHT=2 | |
export KEY_ESCAPE=Escape | |
# Settings | |
export MC=$1 | |
SCRIPT=$2 | |
# GCs | |
export mouseholds=() | |
gc() { | |
for i in "${mouseholds[@]}" | |
do | |
: | |
# mouseup() will remove the item. However, the loop will not be | |
# interrupted. Therefore, a check towards the original array | |
# is always a good idea. | |
if [[ ! " ${mouseholds[@]} " =~ " $1 " ]]; then | |
echo GC: Releasing Mouse \'$i\' | |
mouseup $i | |
fi | |
done | |
} | |
trap gc INT | |
# Setup APIs | |
_disablemouse() { | |
xinput set-prop 12 "Device Enabled" 0 | |
} | |
_enablemouse() { | |
xinput set-prop 12 "Device Enabled" 1 | |
} | |
mousedown() { | |
xdotool mousedown --window $MC $1 | |
if [[ ! " ${mouseholds[@]} " =~ " $1 " ]]; then | |
mouseholds+=($1) | |
fi | |
echo $mouseholds | |
} | |
export -f mousedown | |
mouseup() { | |
xdotool mouseup --window $MC $1 | |
mouseholds=( "${mouseholds[@]/$1}" ) | |
echo $mouseholds | |
} | |
export -f mouseup | |
click() { | |
xdotool click --window $MC $1 | |
mouseholds=( "${mouseholds[@]/$1}" ) | |
} | |
export -f click | |
mousemove_relative() { | |
xdotool mousemove_relative $1 $2 $3 | |
} | |
windowfocus() { | |
xdotool windowfocus $1 | |
} | |
export -f windowfocus | |
key() { | |
xdotool key --window $MC $1 | |
} | |
export -f key | |
# Prepare mouse | |
eval $(xdotool getmouselocation --prefix X_ --shell) | |
# Switch to Minecraft | |
windowfocus $MC | |
# Resume game | |
key $MC $KEY_ESCAPE | |
# This is done instantly. Disable mouse to prevent from accidental moving | |
_disablemouse | |
# Move a little, or attacking will not work | |
mousemove_relative 1 1 | |
mousemove_relative -- -1 -1 | |
# Return | |
windowfocus $X_WINDOW | |
# xdotool mousemove $X_X $X_Y # Will cause mouse events fail. IDK why | |
_enablemouse | |
# End of Prepare mouse | |
# Execute script | |
source $2 | |
# GC | |
gc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment