0

I use every single key on my laptop keyboard, with not one to spare. I recently got a Thinkpad T14 gen 5, which has a copilot key where PrtSc used to be. I was hoping to rebind the copilot key to be PrtSc (which I use heavily to resize windows), or at least map it to something (F23?) that I could intercept with my window manager for the same purposes.

Unfortunately, when I use showkey -s, pressing the copilot key gives 0xe0 0x5b 0x2a, and releasing 0xaa 0xe0 0xdb. I verified that 0xe0 0x5b / 0xe0 0xdb is just what I get for pressing / releasing the left windows key, and 0x2a / 0xaa is what I get for pressing / releasing the left shift key. So there doesn't seem to be a unique scan code for the copilot key.

If I use evtest, I get the following events from pressing/releasing copilot:

Event: time 1733647696.413560, type 4 (EV_MSC), code 4 (MSC_SCAN), value db Event: time 1733647696.413560, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 1 Event: time 1733647696.413560, -------------- SYN_REPORT ------------ Event: time 1733647696.413794, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a Event: time 1733647696.413794, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 1 Event: time 1733647696.413794, -------------- SYN_REPORT ------------ Event: time 1733647696.413922, type 4 (EV_MSC), code 4 (MSC_SCAN), value 6e Event: time 1733647696.413922, -------------- SYN_REPORT ------------ Event: time 1733647696.519973, type 4 (EV_MSC), code 4 (MSC_SCAN), value 6e Event: time 1733647696.519973, -------------- SYN_REPORT ------------ Event: time 1733647696.520192, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a Event: time 1733647696.520192, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 0 Event: time 1733647696.520192, -------------- SYN_REPORT ------------ Event: time 1733647696.520475, type 4 (EV_MSC), code 4 (MSC_SCAN), value db Event: time 1733647696.520475, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 0 

So there is some kind of event unique to pressing copilot (namely MSC_SCAN 0x6e), but this doesn't seem to yield a corresponding keyscan event I can put into a keyboard map to load with loadkeys. If I could map that 0x6e event to F23, I could just have my window manager do the equivalent of the Print key on Win-Shift-F23, but I don't know how to do this.

My questions:

  • What is the relationship between the EV_MSC event values returned by evtest and the scan codes returned by showkey -s?
  • Is there some way to get the kernel to generate a key event from this EV_MSC 6e event? Can I do this with a keymap and loadkeys, or is there something lower-level I need to do?
  • Are there any other ways to be able to intercept the copilot key in my window manager to resize windows?

1 Answer 1

1

It seems that the code 6e I get from evtest is a scancode that can be mapped to a keycode using the setkeycodes utility, and I don't understand what showkey -s is actually doing at all, but it's not outputting scan codes in the sense that setkeycodes/getkeycodes uses the term. Running:

setkeycodes 6e 99 

makes it so that the copilot key maps to PrtSc, and it even allows SysRq commands. E.g., if you press Alt+(copilot, s) [i.e., press Alt, press copilot, release copilot, press s, release s, release Alt], the kernel will sync the disks.

When I went to check that SysRq functionality was working, it turns out journalctl -k actually had messages like "Unknown key pressed... Use 'setkeycodes 6e ' to make it known." So there you have it.

Here's a systemd unit file (/etc/systemd/system/copilot-key.service) that you can enable to do this automatically:

[Unit] Description=Map copilot key to Shift-Win-PrtSc After=local-fs.target [Service] Type=oneshot ExecStart=/usr/bin/setkeycodes 6e 99 ExecStop=/usr/bin/setkeycodes 6e 0 RemainAfterExit=yes [Install] WantedBy=multi-user.target 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.