From: jon@elytron.openbsd.amsterdam Subject: Numpad on macppc laptops To: tech@openbsd.org Date: Mon, 8 Apr 2024 17:24:42 +0000 Hello everyone. This diff is about enabling the numlock and numpad (see some of the keys on the right side of the keyboard in [1]) on these old powerbooks and ibooks. I'd like to begin by explaining the behavior in OSX: The numpad can be used both with numlock and by pressing fn + the marked keys. * If pressing fn, the character sent is merely the digit or +=-/* symbol marked on the key, while fn + other unmarked keys has no effect. * If using numlock, there is no need to press fn, and the rest of the keyboard is pretty much disabled while the marked keys send the number or symbol marked. I'll refer to this later as the "numlock without fn" behavior. In contrast, in the (proof of concept) implementation I present here [2], we always need to press fn, and the behavior pretty much the default openbsd one: * If numlock is not activated, we get the usual numpad keys such as KS_KP_UP or KS_KP_Decimal by pressing the numpad keys plus fn. * If numlock is activated, we get the numbers or +=-/* symbols with the appropiate key, plus fn. * If shift is held, the behavior is reversed. I find this acceptable but would really appreciate other's ideas. I seems that this kind of numpad is present not just in macppc laptops but a bunch of others, including non apple ones, so I wonder if it is of interest to make it separate from the apple_fn_trans table. It might be nice to reverse the shift behavior too and require shift for the numpad arrow keys and so on instead. In order to implement the "numlock without fn" behavior, a few other changes to wskbd.c are needed, but I can give that a shot as well. Another nitpick I can think of is mapping KS_KP_Enter to the comma key. Although not marked, it might be a good idea for completeness (ukbd code 88 I think). [1] https://www.techstar.co.nz/wp-content/uploads/2017/04/lpkbapple01.jpg [2] Index: dev/hid/hidkbd.c =================================================================== RCS file: /cvs/src/sys/dev/hid/hidkbd.c,v retrieving revision 1.12 diff -u -p -r1.12 hidkbd.c --- dev/hid/hidkbd.c 3 Jan 2024 21:41:44 -0000 1.12 +++ dev/hid/hidkbd.c 8 Apr 2024 17:23:42 -0000 @@ -141,9 +141,26 @@ static const struct hidkbd_translation a { 60, 127 }, /* F3 -> audio mute */ { 61, 129 }, /* F4 -> audio lower */ { 62, 128 }, /* F5 -> audio raise */ + { 63, 83 }, /* F6 -> num lock */ { 65, 234 }, /* F8 -> backlight toggle */ { 66, 236 }, /* F9 -> backlight lower */ { 67, 235 }, /* F10 -> backlight raise */ + { 39, 84 }, /* keypad divide */ + { 19, 85 }, /* keypad multiply */ + { 51, 86 }, /* keypad substract */ + { 56, 87 }, /* keypad add */ + { 13, 89 }, /* keypad 1 */ + { 14, 90 }, /* keypad 2 */ + { 15, 91 }, /* keypad 3 */ + { 24, 92 }, /* keypad 4 */ + { 12, 93 }, /* keypad 5 */ + { 18, 94 }, /* keypad 6 */ + { 36, 95 }, /* keypad 7 */ + { 37, 96 }, /* keypad 8 */ + { 38, 97 }, /* keypad 9 */ + { 16, 98 }, /* keypad 0 */ + { 55, 99 }, /* keypad decimal */ + { 45, 103 }, /* keypad equal */ #else { 63, 102 }, /* F6 -> sleep */ { 67, 127 }, /* F10 -> audio mute */