39 lines
1.5 KiB
Bash
Executable File
39 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Type a chat command into Minecraft on a QWERTZ keyboard.
|
|
#
|
|
# ydotool speaks evdev keycodes, which are *positional* and named for a US
|
|
# layout, so `ydotool type` writes whatever the user's layout has at those
|
|
# positions. On QWERTZ that swaps y and z, and '/' is shift+7 rather than a key
|
|
# of its own. Sending the wrong thing does not fail loudly - it posts as chat,
|
|
# which is how "/reload" once went out as "-reload" and "day" as "daz".
|
|
#
|
|
# mc-type.sh "time set day" types /<command> and presses enter
|
|
set -uo pipefail
|
|
export YDOTOOL_SOCKET=${YDOTOOL_SOCKET:-/run/user/1000/.ydotool_socket}
|
|
|
|
declare -A K=(
|
|
[a]=30 [b]=48 [c]=46 [d]=32 [e]=18 [f]=33 [g]=34 [h]=35 [i]=23
|
|
[j]=36 [k]=37 [l]=38 [m]=50 [n]=49 [o]=24 [p]=25 [q]=16 [r]=19
|
|
[s]=31 [t]=20 [u]=22 [v]=47 [w]=17 [x]=45
|
|
[y]=44 [z]=21 # QWERTZ: y and z sit on each other's keys
|
|
[0]=11 [1]=2 [2]=3 [3]=4 [4]=5 [5]=6 [6]=7 [7]=8 [8]=9 [9]=10
|
|
[' ']=57 [.]=52 [_]=12
|
|
)
|
|
|
|
ydotool key 42:0 54:0 # make sure no shift is stuck
|
|
sleep 0.2
|
|
ydotool key 20:1 20:0 # T -> open chat
|
|
sleep 0.9
|
|
ydotool key 42:1 8:1 8:0 42:0 # shift+7 -> '/'
|
|
sleep 0.3
|
|
ydotool key 42:0 54:0 # release shift again, explicitly
|
|
sleep 0.2
|
|
cmd="$1"
|
|
for (( i=0; i<${#cmd}; i++ )); do
|
|
ch="${cmd:$i:1}"
|
|
code="${K[$ch]:-}"
|
|
if [ -n "$code" ]; then ydotool key "$code:1" "$code:0"; sleep 0.04; fi
|
|
done
|
|
sleep 0.4
|
|
ydotool key 28:1 28:0 # enter
|