Substitute the Copilot key's hardwired shortcut with a different key.
The default substitution key is RightControl, but see Use a different key than right control for info on sending an alternative key.
Chances are you stumbled on this repo because you have a god-forsaken copilot key on your keyboard.
In typical Microsoft fashion, this key was implemented in the most annoying way conceivable, namely:
- It does not send a single scan code, but is hard-wired to send LeftMeta+LeftShift+F23
- It does not track when you release the key, so it actually sends down events for LeftMeta+LeftShift+F23, immediately followed by up events for each.
These two qualities make the key almost entirely unusable for anything else other than some other sort of application launcher. This application is an attempt to use this key as a modifier key, given its placement where such a key would normally reside.
Since the key sends the same key chord in the same order each time, and nearly instantly, we don't need much logic to track modifier key state. Basically it watches for the key order LeftMeta→LeftShift→F23 and if this sequence arrives in order, it drops the keys and substitute a different key press in the device stream. Then it schedules a release event of that key in a few milliseconds (default is 300, but this can be supplied as a command line argument). This is necessary because the copilot key itself does not react to when it is released, it sends the key chord up events immediately after the keydown events so it's necessary to simulate a small delay so the user has a chance to press a different key to combine with the substituted modifier key.
Note
It's possible to simulate the behavior of this app using the evsieve tool.
device='/dev/input/by-path/your-keyboard-device-path'
copilot_seq='key:leftmeta key:leftshift key:f23'
copilot_sub_key='key:rightctrl'
evsieve \
--input "$device" grab \
--hook $copilot_seq sequential period=0.1 send-key=$copilot_sub_key \
--withhold \
--delay $copilot_sub_key:0 period=0.3 \
--output name="kbd-no-copilot" create-link="kbd-no-copilot"evsieve is more robust and enables arbitrary complex substitutions.
However, I found that its virtual device circumvented keyboard mappings and rules in my desktop environment,
for example it prevented disabling the touchpad while typing despite having this option explicitly configured.
Hence, I opted to write this tool as a more useful solution.
-
Linux only, operates on evdev devices
-
GNU Make
-
libevdevlibrary:Debian/Ubuntu:
sudo apt install libevdev-dev build-essential
Arch Linux:
sudo pacman -S libevdev
Fedora:
sudo dnf install libevdev-devel
make allThe built executable can be tested from ./build/remap-copilot.
Change the defined value of the COPILOT_REPLACE_KEY macro.
This can be done either in the source code or supplying a value for the USERDEFINES Make variable that will be passed to the compiler.
For example, to use the right alt key instead:
make USERDEFINES="-DCOPILOT_REPLACE_KEY=KEY_RIGHTALT"sudo make installThe default install prefix is /usr/local/. Change the PREFIX Make variable to alter this, for example: sudo make install PREFIX=/usr will install to /usr/bin.
$ make install-systemd
Installed ~/.config/systemd/user/remap-copilot.service
Try:
systemctl --user start remap-copilot
systemctl --user enable --now remap-copilot
$ systemctl --user enable --now remap-copilot.service
Created symlink '~/.config/systemd/user/default.target.wants/remap-copilot.service'Installs a user systemd service that ensures an instance of this program is always running.
make uninstallWill remove the executable from the installation directory, and also removes the user systemd service if it's detected.