Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Question) Remap Copilot key #492

Open
ethanc8 opened this issue Jan 2, 2025 · 10 comments
Open

(Question) Remap Copilot key #492

ethanc8 opened this issue Jan 2, 2025 · 10 comments
Assignees
Labels
question Further information is requested

Comments

@ethanc8
Copy link

ethanc8 commented Jan 2, 2025

Rather than including a right Ctrl key, my laptop comes with a Copilot key. It produces the key combination LShift+LSuper, which toshy converts into LShift+LAlt. I would like to remap this to another combination, but

keymap("User hardware keys", {
    # PUT UNIVERSAL REMAPS FOR HARDWARE KEYS HERE
    # KEYMAP WILL BE ACTIVE IN ALL DESKTOP ENVIRONMENTS/DISTROS
    C("Shift-Alt"):      C("AltGr-Super"),

}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)

does not work since Shift-Alt is a modifier-only sequence. Do I need to multipurpose_modmap Alt to F19?

@ethanc8 ethanc8 added the question Further information is requested label Jan 2, 2025
@RedBearAK
Copy link
Owner

@ethanc8

Oh boy, the Copilot key. That's been coming up on Reddit a lot lately. Blech. Seems to even work differently on different laptops.

Well, first of all, "multipurpose" modmaps are for what other keymappers might call "overloading" a key. Giving it two different identities depending on whether it is tapped within a certain time threshold (defaults to 1 second in the config file) or held past that time (so it can be used with other keys as another modifier, typically). A common remapping is CapsLock to Esc & Ctrl.

Which means you'd just want to do a normal modmap(). But you'd also not want to modmap Alt like that, because that would affect all other uses of the Alt key in every shortcut.

Here's a central problem with such a "macro" key. There's no way that I am aware of to differentiate that LShift+LSuper macro sequence from the Copilot key apart from any other usage of LShift+LSuper. So if you try to change what it does, you'll just be changing what LShift+LSuper does in general.

Is there possibly any kind of firmware or software option to make that key do something else? Unless we can either change what the key does intrinsically, or find a way to identify that specific key being pressed as anything other than a generic LShift+LSuper sequence that you manually type with those actual keys (or the virtualized equivalents, in this case), I am actually not sure at the moment what could be done with it.

I'd like to see the full evtest result of pressing the Copilot key. And what if you press it with Shift, what happens then? That would be a bit weird, since it also issues a Shift press.

The only other time I've seen something like this is when a laptop has some special macro keys, and usually there won't be much that can be done with that, unless there is some software that can disable those macros and turn the keys into regular keys again. Usually this happens on the F-keys row with unusual special functions, and inverting the F-keys functions in the BIOS can offer a mitigation of the problem. In this case I don't know what you can do unless there is something in the BIOS you can tweak.

Many sad faces: 😢 😭 😞 😿

@RedBearAK
Copy link
Owner

@ethanc8

According to some sources, the shortcut that should actually be coming from that key is Shift+Super+F23, which makes a lot more sense than the key just issuing a couple of modifier presses.

https://answers.microsoft.com/en-us/windows/forum/all/copilot-keyboard-shortcut/1d87df9a-7d71-409c-87ab-64023928a287

Modifier-only shortcuts do exist, (and have always been a bad idea, in my opinion), but if the Copilot key only does LShift+LSuper, how would the shell, even in Windows, know that you wanted to perform an action? And that same action would happen if you just pressed the actual Shift and Super (Meta/Win/Cmd) keys together. Every time you pressed them without adding a non-modifier key to make a "combo".

So I would try this:

keymap("User hardware keys", {
    # PUT UNIVERSAL REMAPS FOR HARDWARE KEYS HERE
    # KEYMAP WILL BE ACTIVE IN ALL DESKTOP ENVIRONMENTS/DISTROS

    # Catch and remap Copilot key shortcut?
    C("Shift-Alt-F23"):      C("RAlt-Super-F23"),

}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)

If you use toshy-debug and see that combo remap being triggered when you tap the Copilot key, then you can change the output of the remap to whatever you want.

It's still probably not really possible to force it to be a Ctrl key that would be usable in any combo. And modmaps are definitely not set up to be able to remap a combo of keys to be a single key, which could then be seen as that key in shortcuts. But you could use the key to trigger a macro of keystrokes, type a string, run a function, or just redirect to another combo like in the example above. Anything you can normally do with a remap in a keymap().

BTW, there's no AltGr modifier alias. If you do have an Alt_Gr on your keyboard layout, you'd use that in a remap via RAlt like I've shown in the example. That will "press" the Alt key on the right side of the keyboard, which the desktop environment can then interpret as an Alt_Gr key press. If it is set up to do so. That's not up to the keymapper. It just "types" on the low-level virtual keyboard on your behalf, like a ghost.

@ethanc8
Copy link
Author

ethanc8 commented Jan 3, 2025

This is what evtest returns:

Properties:
Testing ... (interrupt to exit)
Event: time 1735864156.175018, type 4 (EV_MSC), code 4 (MSC_SCAN), value 1c
Event: time 1735864156.175018, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0
Event: time 1735864156.175018, -------------- SYN_REPORT ------------
Event: time 1735864158.145505, type 4 (EV_MSC), code 4 (MSC_SCAN), value db
Event: time 1735864158.145505, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 1
Event: time 1735864158.145505, -------------- SYN_REPORT ------------
Event: time 1735864158.148626, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a
Event: time 1735864158.148626, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 1
Event: time 1735864158.148626, -------------- SYN_REPORT ------------
Event: time 1735864158.150858, type 4 (EV_MSC), code 4 (MSC_SCAN), value 6e
Event: time 1735864158.150858, -------------- SYN_REPORT ------------
Event: time 1735864158.245292, type 4 (EV_MSC), code 4 (MSC_SCAN), value 6e
Event: time 1735864158.245292, -------------- SYN_REPORT ------------
Event: time 1735864158.252552, type 4 (EV_MSC), code 4 (MSC_SCAN), value 2a
Event: time 1735864158.252552, type 1 (EV_KEY), code 42 (KEY_LEFTSHIFT), value 0
Event: time 1735864158.252552, -------------- SYN_REPORT ------------
Event: time 1735864158.261347, type 4 (EV_MSC), code 4 (MSC_SCAN), value db
Event: time 1735864158.261347, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 0
Event: time 1735864158.261347, -------------- SYN_REPORT ------------

I don't see any F23 there. Does this mean it's sending LShift+LMeta+Enter?

@ethanc8
Copy link
Author

ethanc8 commented Jan 3, 2025

@ethanc8

According to some sources, the shortcut that should actually be coming from that key is Shift+Super+F23, which makes a lot more sense than the key just issuing a couple of modifier presses.

https://answers.microsoft.com/en-us/windows/forum/all/copilot-keyboard-shortcut/1d87df9a-7d71-409c-87ab-64023928a287

Modifier-only shortcuts do exist, (and have always been a bad idea, in my opinion), but if the Copilot key only does LShift+LSuper, how would the shell, even in Windows, know that you wanted to perform an action? And that same action would happen if you just pressed the actual Shift and Super (Meta/Win/Cmd) keys together. Every time you pressed them without adding a non-modifier key to make a "combo".

I'd assume the same way it differentiates between pressing Super to open the start menu and pressing Super as part of a combo.

So I would try this:

keymap("User hardware keys", {
    # PUT UNIVERSAL REMAPS FOR HARDWARE KEYS HERE
    # KEYMAP WILL BE ACTIVE IN ALL DESKTOP ENVIRONMENTS/DISTROS

    # Catch and remap Copilot key shortcut?
    C("Shift-Alt-F23"):      C("RAlt-Super-F23"),

}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)

If you use toshy-debug and see that combo remap being triggered when you tap the Copilot key, then you can change the output of the remap to whatever you want.

It's still probably not really possible to force it to be a Ctrl key that would be usable in any combo. And modmaps are definitely not set up to be able to remap a combo of keys to be a single key, which could then be seen as that key in shortcuts. But you could use the key to trigger a macro of keystrokes, type a string, run a function, or just redirect to another combo like in the example above. Anything you can normally do with a remap in a keymap().

BTW, there's no AltGr modifier alias. If you do have an Alt_Gr on your keyboard layout, you'd use that in a remap via RAlt like I've shown in the example. That will "press" the Alt key on the right side of the keyboard, which the desktop environment can then interpret as an Alt_Gr key press. If it is set up to do so. That's not up to the keymapper. It just "types" on the low-level virtual keyboard on your behalf, like a ghost.

I want to set it up to be a Compose key. These are the options in KDE:

image

I wanted to choose "Third level of Right Win", which is equivalent to AltGr+RSuper.

@ethanc8
Copy link
Author

ethanc8 commented Jan 3, 2025

This is what happens when I run toshy-debug:

$ toshy-debug 
Stopping Toshy systemd services...
Toshy systemd services stopped.
xwaykeyz v1.3.5
(DD) CONFIG: /home/ethan/.config/toshy/toshy_config.py
(DD) THROTTLES: Pre-key: 12ms, Post-key: 18ms
(DD) No Synergy log folder found. No log observer will be engaged.

(CG) Current settings:
        ------------------------------------------------------------------------------
        calling_module          = 'toshy_config.py'
        prefs_db_file_path      = '/home/ethan/.config/toshy/toshy_user_preferences.sqlite'
        ------------------------------------------------------------------------------
        autostart_tray_icon     = True
        gui_dark_theme          = True
        ------------------------------------------------------------------------------
        override_kbtype         = 'Auto-Adapt'
        ------------------------------------------------------------------------------
        optspec_layout          = 'Disabled'
        mru_layout              = ('us', 'default')
        ------------------------------------------------------------------------------
        forced_numpad           = True
        media_arrows_fix        = False
        multi_lang              = False
        Caps2Cmd                = False
        Caps2Esc_Cmd            = False
        Enter2Ent_Cmd           = False
        ST3_in_VSCode           = False
        ------------------------------------------------------------------------------
        

(CG) Toshy config sees this environment:
        DISTRO_ID        = 'opensuse-tumbleweed'
        DISTRO_VER       = '20241224'
        VARIANT_ID       = 'notfound'
        SESSION_TYPE     = 'wayland'
        DESKTOP_ENV      = 'kde'
        DE_MAJ_VER       = '6'
        WINDOW_MGR       = 'kwin_wayland'

(DD) ENVIRON: Session type: 'wayland', Desktop env: 'kde'
(ID) Machine ID read from /var/lib/dbus/machine-id (obfuscated): '14d61 ... df4df'
(ID) Hashed value for this machine, for use in your config file: '634d2827'
(DD) Zenity command path: '/usr/bin/zenity'
(--) WATCH: Watching for new devices to hot-plug.
(--) Autodetecting all keyboards (no '--devices' option or 'devices_api' used)
(+K) Grabbing 'AT Translated Set 2 keyboard' (/dev/input/event0)
(+K) Successfully grabbed 'AT Translated Set 2 keyboard' (/dev/input/event0)
(--) Ready to process input.

(II) in LEFT_META (press)
(CX) KDE_DBUS_SVC: Using D-Bus interface 'org.toshy.Plasma' for window context
(DD) KBTYPE: 'Windows' | Rgx matched on dev: 'AT Translated Set 2 keyboard'
(DD) MODMAP: LEFT_META => LEFT_ALT [Cond modmap - GUI - Win kbd]
(DD) on_key LEFT_ALT press
(DD) suspending keys: [VLOpt<Key.LEFT_ALT>]

(II) in LEFT_SHIFT (press)
(CX) KDE_DBUS_SVC: Using D-Bus interface 'org.toshy.Plasma' for window context
(DD) KBTYPE: 'Windows' | (CACHED) Rgx matched on dev: 'AT Translated Set 2 keyboard'
(DD) on_key LEFT_SHIFT press
(DD) resuspending keys
(DD) suspending keys: [VLOpt<Key.LEFT_ALT>, LShift<Key.LEFT_SHIFT>]
(DD) resuming keys: [<Key.LEFT_ALT: 56>, <Key.LEFT_SHIFT: 42>]
(OO) press LEFT_ALT 1735864434.9078124
(OO) press LEFT_SHIFT 1735864434.9079645

(II) in LEFT_SHIFT (release)
(CX) KDE_DBUS_SVC: Using D-Bus interface 'org.toshy.Plasma' for window context
(DD) on_key LEFT_SHIFT release
(DD) resume because of mod release
(OO) release LEFT_SHIFT 1735864434.956485

(II) in LEFT_META (release)
(CX) KDE_DBUS_SVC: Using D-Bus interface 'org.toshy.Plasma' for window context
(DD) on_key LEFT_ALT release
(DD) resume because of mod release
(OO) release LEFT_ALT 1735864434.9639964

@ethanc8
Copy link
Author

ethanc8 commented Jan 3, 2025

Yeah, this doesn't work:

keymap("User hardware keys", {
    # PUT UNIVERSAL REMAPS FOR HARDWARE KEYS HERE
    # KEYMAP WILL BE ACTIVE IN ALL DESKTOP ENVIRONMENTS/DISTROS
    
    # Catch and remap Copilot key shortcut?
    C("Shift-Alt-F23"):      C("Shift-Super-Print"),
}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)

(Shift-Super-Print launches Spectacle, the KDE screenshot program, in rectangular region capture mode.)

@RedBearAK
Copy link
Owner

The way that evtest and toshy-debug are seeing the key events from that key, it doesn't look like you can do anything with it. If evdev based keymappers can't see anything but a press and release of LSuper+LShift, it would be up to your desktop environment to perhaps set that as a modifier-only shortcut to do something. The keymapper behind Toshy can't modmap a pair of modifiers onto anything, that's just not how the code works. And as you've seen modifiers without a "normal" key involved can't be seen as a "combo" shortcut.

It's definitely not doing LShift+LMeta+Enter because that Enter key press comes before the modifiers in the evtest logging.

I'd assume the same way it differentiates between pressing Super to open the start menu and pressing Super as part of a combo.

Yeah, that only works in a desktop environment where they have somehow implemented the ability to respond to a modifier-only shortcut. Xubuntu does it with a third-party utility, GNOME has the Super key shortcut built directly into the shell, and doesn't support other kinds of modifier-only shortcuts. Cinnamon might have it hard-coded into the app launcher menu applet, I'm not sure. Plasma just implemented full support for all modifier-only shortcuts (other than Super/Meta/Win/Cmd, which was previously hard-coded) very recently. I think that came in Plasma 6.1.

You're using Plasma 6, so in theory you can have Plasma recognize it as a modifier-only shortcut. It will still come out as LAlt+LShift as long as Toshy is enabled and doing it's modifier remapping. That could present its own problem. I think there's a bug in Plasma right now that causes Alt+Shift to not be recognized as a shortcut, while Shift+Alt works, and there's no way to change the order of the keys that the Copilot macro will send out. I thought that bug was fixed but I've seen multiple posts on Reddit lately with people complaining about that.

And then of course there would still be the issue that the same modifier-only shortcut would be triggered if you ever press and release the real Alt+Shift keys without creating a full combo.

It's really bizarre to me that there isn't a full shortcut coming from the key, or at least that evdev can't detect the F23 that is supposedly part of what the Copilot key is designed to emit. That doesn't really make much sense if the Windows shortcut is specified to be Shift+Win+F23. The only thing I can think of is that the firmware of the computer is somehow intercepting the F23 key event. Like what happens with a lot of the special hardware functions on PC laptop keyboards. They often don't get seen as key events by the Linux input system.

Without finding some other software that can modify or detect the Copilot key press as a unique thing, I don't know what else to offer you as a way to make it useful. That's very frustrating.

@RedBearAK
Copy link
Owner

RedBearAK commented Jan 31, 2025

@ethanc8

I am very surprised by this new information, but it looks like the problem with detecting the Copilot key macro in Linux, at least the F23 part, was because the Linux kernel was ignoring the F23 scan code. It just wasn't in the atkbd driver in the kernel. So it's not the Linux keymapper's fault, or the fault of evdev. In Linux they literally can't see the F23 key press portion of the macro that comes from the Copilot key, because the kernel is not interpreting the scan code (0x6e) and turning it into keycode 193.

Supposedly this will be patched in kernel 6.14, so this will become a question of how soon any particular Linux distro will make that kernel version available, or whether this patch will be backported to any earlier kernel versions. If you're on something like Arch, Tumbleweed or Fedora (particularly Fedora Rawhide) you'd probably be one of the first to see the kernel with the patch.

A Brodie Robertson video on YouTube clued me in to the cause, and the fix that should be coming.

References:

https://www.theregister.com/2025/01/24/copilot_key_linux/

https://www.phoronix.com/news/Linux-6.14-Input

https://patchwork.kernel.org/project/linux-input/patch/[email protected]/

If I understand the situation correctly, once anyone gets this patch in their kernel, the LShift-LSuper-F23 combo that comes out of the Copilot key as a macro will finally be seen by the keymapper, and it will be possible to remap the macro to anything the user wants.

I don't know what I was thinking earlier with the example remap, but the following keymap should cause the Toshy diagnostic dialog (a zenity info dialog) to appear when pressing the Copilot key:

keymap("Copilot key test keymap", {
    C("Shift-Super-F23"):      notify_context,    # Show the diagnostic dialog when pressing Copilot key
}, when = lambda ctx:
    cnfg.screen_has_focus and
    matchProps(not_clas=remoteStr)(ctx)
)

Once it actually starts working, the remap can be changed to anything like a typical combo or macro. Or the remap could be removed, and the Shift-Super-F23 shortcut could be directly assigned to some native action in the desktop environment, without involving the keymapper at all.

But the Copilot key still won't be usable as a modifier key with this keymapper, since modmap() isn't designed to remap a macro key combo on the input side. It will not be possible to turn it back into a Ctrl key that could be used as part of other key combos, for instance. So it will still just kind of be a lame macro key that will need to be assigned to a specific action to be useful.

@ethanc8
Copy link
Author

ethanc8 commented Jan 31, 2025

Ok, great! I wonder if I can configure KDE, IBus, or fcitx5 to recognize it as a Compose key; otherwise, I might just map it to open the start menu or open Spectacle. Also, some kernel modules I need have stopped building on newer versions of Tumbleweed so I'm stuck on an older version for now.

@RedBearAK
Copy link
Owner

I wonder if I can configure KDE, IBus, or fcitx5 to recognize it as a Compose key

That seems unlikely. Like Alt_Gr, I'm pretty sure the Compose key needs to just be "a key", and only certain keys will work at that. But maybe there is some magic in the input managers that I don't know about. Or maybe they will implement some specifically for this disaster of a macro key. 😆

Fedora is still on 6.12.x in stable, and only beginning to use 6.13 recently in Rawhide, I think. It will probably be some time before 6.14 is available in anything as the stable kernel branch. Maybe a month or two, at best, in most of the leading-edge distros.

I'm more curious whether the patch will be backported to any LTS kernel versions. You won't be getting kernel 6.14 even on AlmaLinux/RHEL/CentOS Stream 10 beta, but I'm sure many Linux users will want to run distros like that on a device with a Copilot key. So it's a weird situation.

Do let me know if at some future date you get 6.14 and find that the Copilot key's F23 key press is detectable. I'll continue to keep this issue open until it's clear the solution is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants