0

I am using keyfuzz to map Alt-Eject to Alt-SysRq in Mac keyboard (See here). But on recent (X)ubuntus it is preferred to use systemd service to run the needed command at startup. I wonder how early I can put that service to be executed? Like which WantedBy=, After=, Before= and such attributes to use so that the configuration works and will not be overwritten? Will it work even in rescue mode boot then?

here is some reference about dependencies between different targets.

Edit: I put WantedBy=multi-user.target friendly-recovery.target in [Install] section of the .service file I created. That seems to work also in recovery mode root shell.

jarno
  • 5,600
  • My intuition says somewhere after udevd. However, instead of relying on a device (e.g. keyboard) being present at a specific target, I'd hook into udev so you can do something as soon as the device is attached. For remapping scancode->keycode, you can simply use a Hardware Database (hwdb) entry (which will also work in rescue mode). Take a look at /lib/udev/hwdb.d/60-keyboard.hwdb for some usage examples. – danzel Aug 30 '19 at 11:46
  • please use the answer section for answers and not an edit. the system will keep this question queued instead of it having an answer people can upvote and you can acccept – Rinzwind Sep 01 '19 at 09:05
  • @danzel I tried that in an answer, but I could not get it work. – jarno Sep 01 '19 at 16:59

2 Answers2

0

I put WantedBy=multi-user.target friendly-recovery.target in [Install] section of the .service file I created. That seems to work also in recovery mode root shell. Still, I don't know, if this is the best configuration to use.

jarno
  • 5,600
0

Instead of using keyfuzz I tried to remap scancode->keycode like danzel advised in a command, and according to instructions in /lib/udev/hwdb.d/60-keyboard.hwdb and in here.

I created file /etc/udev/hwdb.d/10-apple-keyboard.hwdb with the following contents:

evdev:name:Apple, Inc. Apple Internal Keyboard / Trackpad:dmi:bvn*:bvr*:bd*:svnAppleInc.:pn*
 KEYBOARD_KEY_c00b8=sysrq

For the file I got the device name from the third line of the output of sudo evtest /dev/input/by-id/usb-Apple__Inc._Apple_Internal_Keyboard___Trackpad-evenkbd, the scancode of the eject key by the same command - see related answer - and keycode from /usr/include/linux/input-event-codes.h (in lowercase and without 'key_' prefix in above.)

But still pressing the eject button triggers KEY_EJECTCD and not KEY_SYSRQ as shown by sudo uvtest:

Event: time 1567436214.147340, type 4 (EV_MSC), code 4 (MSC_SCAN), value c00b8
Event: time 1567436214.147340, type 1 (EV_KEY), code 161 (KEY_EJECTCD), value 1
Event: time 1567436214.147340, -------------- SYN_REPORT ------------

I can not confirm the key mapping:

udevadm info /dev/input/by-id/usb-Apple__Inc._Apple_Internal_Keyboard___Trackpad-event-kbd | grep KEYBOARD_KEY

That does not display anything.

jarno
  • 5,600
  • I wonder, what is wrong with this configuration. Is the remapping somehow overwritten by DE or Xorg? – jarno Sep 02 '19 at 15:02