The officially official Devuan Forum!

You are not logged in.

#1 2019-05-17 00:24:56

GNUser
Member
Registered: 2017-03-16
Posts: 570  

basic keylogger/hotstrings shell script (e.g., for Esperanto input)

For any Esperantists out there: There are various ways of entering Esperanto characters in GNU/Linux, but I couldn't find how to do it with the x-system. Therefore, I cooked up a barebones shell script that does the job. As long as the script is running, you can use the x input method.

For example, if you type ehxosxangxocxiujxauxde, you get eĥoŝanĝoĉiuĵaŭde

Feel free to use my shell script below, which I hereby release into the public domain. Simply name the script "iksilo", make it executable, and run!

The script is tested and working in Devuan ASCII and OpenBSD 6.5, but should work in any UNIX-like OS using the X window system. (To use it in OpenBSD, simply change stdbuf to gstdbuf.)

#!/bin/sh

# Deps: coreutils, xdotool, dzen2
# Usage: iksilo start|stop

keyboard_id=9 # use 'xinput list' to find your keyboard's id. uzu 'xinput list' por trovi la id-numeron de via klavaro.

# 1. die gracefully 
dzen2_pid_file=/tmp/iksilo-dzen2-pid
die() { setxkbmap -option; kill $(cat $dzen2_pid_file); pkill -KILL -f iksilo; }
trap die INT HUP TERM; [ "$1" = "stop" ] && die

# 2. add the necessary keyboard options 
setxkbmap -option lv3:ralt_switch,esperanto:qwerty

# 3. simulate an array using variable names: mappings_38=a mappings_39=s mappings_40=d etc.
xmodmap -pke >/tmp/keymap
while read line; do
	keycode="$(echo $line | cut -d' ' -f 2)"
	key="$(echo $line | cut -d' ' -f 4)"
	eval mappings_"$keycode"="$key"
done </tmp/keymap
rm /tmp/keymap

# 4. create indicator
echo "IKSO" | dzen2 -fg "white" -bg "green" -w 40 -h 20 -x 1235 -y 755 -p -e '' & echo $! >$dzen2_pid_file

# 5. go!
replace() { xdotool key BackSpace BackSpace "$1"; }
memory="--"

xinput test $keyboard_id | stdbuf -oL awk '/press/ {print $3}' | while read keycode; do
	key=$(eval echo \$mappings_$keycode)
	memory=$(echo "${memory}${key}" | grep -o '..$')
	case $memory in
		cx) replace ISO_Level3_Shift+c ;;
		gx) replace ISO_Level3_Shift+g ;;
		hx) replace ISO_Level3_Shift+h ;;
		jx) replace ISO_Level3_Shift+j ;;
		sx) replace ISO_Level3_Shift+s ;;
		ux) replace ISO_Level3_Shift+u ;;
	esac
done

Karaj samideanoj, nomu la supran programeton "iksilo", igu ĝin rulebla, kaj rulu ĝin. Dum la programeto rulas, vi povas uzi la ikso-sistemon por tajpi esperantajn literojn ie ajn ene de X.org.  Nur certigu (per la eligaĵo de xinput list), ke la numero post keyboard_id= estas korekta por vi--ĉe mia komputilo, X.org vidas la klavaron kiel enigilo id=9, sed eble ĉe vi la numero estas alia. Por uzi la programeton en OpenBSD, simple ŝanĝu stdbuf al gstdbuf.

Last edited by GNUser (2019-06-11 15:01:58)

Offline

Board footer