GUIVT and TTYVT are swapped
GUIVT="${GUIVT:-2}"
TTYVT="${TTYVT:-1}"
switchtty() {
currentvt=$(cat /sys/devices/virtual/tty/tty0/active)
if [ "$currentvt" = "tty2" ]; then # switch to tty1 with normal UI
chvt "${TTYVT}"
killall "$KEYBOARD"
else # Switch to tty2 with $KEYBOARD
setfont "$FONT" -C /dev/tty2
chvt "${GUIVT}"
Shouldn't GUIVT be the tty of where you have the GUI?
First part has "switch to tty1 with normal UI" and changes to TTYVT: chvt "${TTYVT}"
.
And the second has "Switch to tty2 with KEYBOARD" and changes to `chvt "{GUIVT}"`.
So I think that GUIVT and TTYVT should be swapped.