2

So I just created a file on my desktop with a new extension, and this is what its context menu looks like:

enter image description here

I can bring up the context menu with the menu key on my keyboard, and I can actually select some of the items in the context menu by pressing keys after that. Naturally, this gives me the opportunity to create some keyboard shortcuts. However, I don't quite understand how they work. Take the following example.

If I create a file called "item.newextension" and then import the following registry file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\SystemFileAssociations\.newextension\shell\Edit\command]
@="notepad.exe \"%1\""

[HKEY_CURRENT_USER\SOFTWARE\Classes\SystemFileAssociations\.newextension\shell\Contemplate\command]
@="mspaint.exe \"%1\""

I get some inconsistent and interesting results. To be on the same page, now my context menu looks like this:

enter image description here

If I open the context menu and press the key "e", notepad opens up immediately. Also, if I open the context menu and press the key "c", the context menu flips between "contemplate" and "copy," but does not choose either until I press enter.

So I realize that, if you look closely, there is a little line under each letter in the context menu entry that corresponds to what key needs to be pressed to select it, and when there's overlap, pressing that key repeatedly toggles between the two. So I have a few questions:

  1. When I create my own context menu entries, as I did in the .reg file, how do I select which key is responsible for selecting that entry?
  2. Can I change existing keyboard shortcuts for things like "Create shortcut" and "Copy," or will they always have to be "s" and "c" respectively?

I am on Windows 10 1803 Build 17134 for reference.

2

If there are multiple context menu items with the same hotkey, pressing that hotkey will toggle between them as you discovered. If a hotkey only corresponds to one item, pressing it will immediately trigger the item.

Evidently, Windows is using the first letter of the item's text as the hotkey. You can override that by placing an ampersand (&) before the letter that you want to become the hotkey. However, this must be done in the default value of the command's Registry key, not the key name. In this image, I've tried to change the hotkey for Contemplate to O and the hotkey for Edit to I:

using an ampersand in the key name or the default value seems to work

Both appear to work in that the above configuration produces this context menu:

the changes take effect visually

Pressing O immediately triggers Contemplate, but pressing I does nothing even though no other item in my menu uses I. Changing Edit to have an ampersandless key name but a default value of Ed&it makes it work as expected.

There is not a straightforward way to change the built-in context menu items like Copy; they are not in the Registry and are instead generated by Explorer. You might be able to write a shell extension that uses SetMenuItemInfo with appropriate menu information structures to change it at runtime. For an older answer, I wrote a shell extension to change built-in items' icons that might be a good starting point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.