Alt as a real “modifier” in Plan 9 programs

Alt acts as a “compose” key by default, and there is little to no way to change this. At the same time, a small hack can be used to cancel the compose mode by fake-pressing Alt through /dev/kbin: writing the scancode of the key to it. Whether it works (or not) in drawterm is left as an exercise to the reader, as usual.

For this to work, your program needs to read /dev/kbd directly, and keep /dev/kbin open for writing.

Both orca and FT2 clone are using this approach. You can test it by comparing “Alt, 1, 2” and “Alt, Alt, 1, 2” in a rio window.

The scancode is easy to find:

; g '(KF|Kalt)=' /sys/include/keyboard.h
/sys/include/keyboard.h:23: 	KF=	0xF000,	/* Rune: beginning of private Unicode space */
/sys/include/keyboard.h:38: 	Kalt=	KF|0x15,
; grep `{echo 'dec(0xf000|0x15)' | pc -n} /dev/kbmap 
      0          56       61461
      0          70       61461
      1          56       61461
      1          70       61461
      4          56       61461

An example of the logic:

if(r == Kalt)
	write(kbin, "\x46", 1);

Happy hacking.

Last update: May 16, 2022 05:58PM

December 21, 2022 07:56PM
i'm a furry fox femboy
Leave a comment. Email addresses are not stored.