randyrants / sharpkeys

SharpKeys is a utility that manages a Registry key that allows Windows to remap one key to any other key.
http://www.randyrants.com/
Microsoft Public License
6.15k stars 409 forks source link

No, the Copilot key cannot be remapped, but you can workaround it! #560

Open randyrants opened 6 months ago

randyrants commented 6 months ago

Hi SharpKeys fans!

Sorry to report that the new Copilot key that is appearing on new PC's is not remappable by SharpKeys.

The Copilot key's scancode is a combination of Ctrl + Windows + F23 and the Windows technology the SharpKeys exposes only supports remapping an entire key and not a modified combination of the key.

pavi2410 commented 6 months ago

PowerToys' Keyboard Manager tool is able to remap the Copilot key but that doesn't work for all apps consistently.

https://www.reddit.com/r/olkb/s/tPXmeJ0UGf

Also note:

It seems that

R Ctrl + R Shift + P works

but

R Ctrl + L Shift + P doesn't

Ronjar commented 3 months ago

Remapping only the F23 Key (00_6E) worked for me, although I have no idea why. Worked on a Lenovo Ideapad 5, maybe others could also try and report.

DreymaR commented 3 months ago

You know, that kind of makes sense. If the Copilot key sends Ctrl+Shift+F23 and you remap F23, then in theory you'd get Ctrl+Shift+NewKey. If that's okay, then it should work.

Or are you saying that the Ctrl+Shift gets removed somehow?

This reminds me of remapping the RAlt, which works as a remap for AltGr even though AltGr technically sends LCtrl+RAlt.

randyrants commented 3 months ago

Well, that's an interesting twist.

Yes, it does make sense, and I just tried it on a recent Surface Laptop (Intel-based) - it works fine.

However, if there are other apps/keyboards using F23 for whatever reason, it will impact that functionality as well, so it's a mixed bag. I think it's a slam dunk on laptops, which will likely never have an F key above 12, but not for someone with that 122 key IBM Model M, which has a dedicated F23 key.

DreymaR commented 3 months ago

Such a keyboard won't have a Copilot key! However, I suspect you could use Ctrl+Shift+F23 to get its functionality then.

myusrn commented 1 month ago

Remapping only the F23 Key (00_6E) worked for me, although I have no idea why. Worked on a Lenovo Ideapad 5, maybe others could also try and report.

Well, that's an interesting twist.

Yes, it does make sense, and I just tried it on a recent Surface Laptop (Intel-based) - it works fine.

However, if there are other apps/keyboards using F23 for whatever reason, it will impact that functionality as well, so it's a mixed bag. I think it's a slam dunk on laptops, which will likely never have an F key above 12, but not for someone with that 122 key IBM Model M, which has a dedicated F23 key.

I tried this on msft surface laptop 7th edition (snapdragon x elite silicon based) and it did not work. Specifically, I tried mapping "Function: F23 (00_6E)" to "Special: Right Windows (E0_5C)", so i'd have keyboard symmetry on left and right side of space bar, and after reboot no luck. As in hitting that key now does nothing and hitting ctrl+alt+remapped copilot key launches the microsoft 365 store app.

Previously with other keyboards like msft sculpt desktop ergnomic wireless keyboard and lenovo laptop i was able to remap their context menu "Special: Application (E0_5D)" and print screen "Special: PrtSc (E0_37)" keys occupying same location as copilot key on new copilot+pc keyboards to the "Special: Right Windows (E0_5C)" key, again to produce keyboard symmetry, and it worked in those cases.

randyrants commented 1 month ago

Copilot key shares a home with the Application key. After remapping, make sure that Fn-Lock is off:

If you want it to be a Windows key no matter what state Fn is in, remap the F23 and the Application keys to Right Windows.

myusrn commented 1 month ago

Copilot key shares a home with the Application key. After remapping, make sure that Fn-Lock is off:

  • With Fn-Lock off, it's the Copilot key
  • With Fn-Lock on, it's the Application key

If you want it to be a Windows key no matter what state Fn is in, remap the F23 and the Application keys to Right Windows.

Tried it again and did a full reboot to ensure it wasn't just a sign out / sign back in related issue. Ensured function key is off and it does nothing. Turn function key on and the application context menu behavior works as expected.

Then i tested mapping it to left windows key, no change. Then i tested mapping it to right ctrl key and that worked. A reasonably useful remapping option. Seems like the left/right windows key code remapping isn't working in my case. Any thoughts on why that might be, e.g. windows on arm or 24H2 26100.2033 build specific maybe?

DreymaR commented 1 month ago

Are you sure it works fully though? If the Copilot key really sends Ctrl+Shift+F23, then remapping F23 to something else should keep the Ctrl+Shift modifiers for the remapped key.

Ctrl(+Shift)+Windows does nothing as far as I can tell. Shift+Ctrl may work like the unshifted version, but not always. Are you saying that you get the unshifted version with that remap? If so, may the Shift state be lost but not the Ctrl state, ruining Windows key but not Ctrl key function?

myusrn commented 1 month ago

Hi @DreymaR and @randyrants, thanks for the responses.

First off i'd like to level set that installing the power toys store app on msft surface 7 snapdragon x arm64 device and using keyboard manager > remap shortcuts > select > hitting copilot key on right side of right side alt key says its keycodes consist of Win (Left) + Shift (Left) + F23. This seems different than what is discussed in above in this issue where i'm seeing it is considered to be Ctrl+Shift+F23.

That said yes I expect that sharpkeys remapping of msft surface laptop 7 snapdragon x arm64 device's copilot key to right Ctrl key worked for the reason you mentioned in response above. That is Win+Shift+Ctrl gets interpreted in some desktop state scenarios, e.g. notepad, as simply a Ctrl key press. I tested Win+Shift+Ctrl+C[opy]/V[paste] using Win (Left) key on my device in similar desktop state scenarios, e.g. notepad, and I get the same result as copilot key remapped to Ctrl+C[opy]. This does not hold true for other desktop state scenarios, e.g. teams chat copy to outlook email paste.

Conversely remapping copilot key to WIn (Right) would in theory be producing Win+Shift+Win combination which doesn't get interpreted as just the Windows key press. I tested Win+Shift+Win combination using Win (Left) key on device and it does the same thing that that having remapped the F23 key to Win (Right) key, which was nothing.

So i've installed power toys store app and used keyboard manager shortcuts configuration option to remap the copilot key's Win (Left) + Shift (Left) + F23 sequence to simply Ctrl (Right). I used the keyboard manager keys option to remap fn+copilot key [ Apps/Menu ] behavior to Win (Right) and that is doing the trick. Not sure what the overhead is of having PowerToys.Runner system tray daemon running to support these shortcut/key remappings does in terms of impacting battery life, presumably it's negligible.

randyrants commented 1 month ago

In so far as I know, Copilot's multi-key short cut is WIN+C and the Copilot key itself is F23.

When Windows remaps a key, it remaps the entire key, so it remaps CTRL or C but cannot remap CTRL+C. This is done at a very low level within Windows, and why combinations after the remapping are effective. I think.

Power Toys (and AutoHotKey) is using an additional bit of code that is an active remapper, so it can do modified keys, but there's no guarantee that when combinations of modified keys may be hard to predict, similar to how swapping keys in SharpKeys may take some trial and error. I mean, think about sending in three modified keys into the Power Toys module: depending on how they get queued up it could end up weird. And there's no order of operations for keyboard presses like there is for math. Like when you look at 3 +7 * 10 there are rules to guarantee the answer is 73 and not 100 but for scancodes typed, the queue may get filled differently at different times..

myusrn commented 1 month ago

Hi @randyrants thanks for clarifications and additional details. Ultimately it would be best if I could just use a SharpKeys applied physical key remapping to get that copilot key doing something more useful like a right side CTRL given keyboard doesn't include that.

Especially given if someone is wanting keyboard shortcut for launching copilot app, which appears to just be a native client app wrapper of web browser control, they can just use the WIN+C[opilot] keyboard shortcut that covers that.

Not sure what else I might experiment with since I did try using SharpKeys to remap copilot key [ / F23 ] to CTRL and it works in apps like notepad, where it seems the Win (Left) + Shift (Left) modifiers being included doesn't make a difference, but not in apps like outlook and teams, where it seems those modifiers do block interpretation of a simple CTRL key for use as a C, V or X key modifier.

I noticed that unlike SharpKeys key remapping which works right away when you login to the shell the PowerToys keyboard manager remapping of Win (Left) + Shift (Left) + F23 on my surface 7 snapdragon X arm64 device takes 30sec of so to take effect. Essentially however much time it takes for system from a new shell logging session to get around to launching the PowerToys system tray daemon.

randyrants commented 1 month ago

Again, SharpKeys is not remapping anything: it is simply an app that exposes the Registry value that Windows uses to remap the key. This is why there needs to be a reboot, while Power Toys and AutoHotKeys are actively loading an additional bit of code to remap the key above Windows.

As I've already called out that the Copilot key's code is supposed to be CTRL+WIN+F23, so I didn't expect Windows to remap this key. That you can sort of workaround it by remapping F23, I don't think it's going to remap that well, because it's actually going to be CTRL+WIN+whatever-key-you-remapped, which is likely OK for most usage, but it really depends on what key it gets remapped to and the app that's open when you hit it. e.g. I would imagine that something like Photoshop or Visual Studio, which I expect has a ton of shortcuts, would throw a fit for a remapped key. Like if you remapped to N, you'd now be hitting CTRL+WIN+N and who knows what the app will do.