Add keyboard shortcuts to menus#14490
Conversation
Change SaveAs accelerator key from ctrl-A to ctrl-shift-S ctrl-A is the 'select all' editor command and is hooked by the editor before the File menu sees the ctrl-A. Shortcut keys are language specific and defined in the resource files. Add the shortcut keys to the default resource files.
|
Nice initiative - short cuts for menu items have been sorely missing. However, I'm a little worried that defining menu short-cuts like Yours, |
We have to frame this discussion solely around the Player window. That window specifically has the potential conflicts with modules. The Player window has three top level menu items, in English File, Tools, and Help. That's Alt-F, Alt-T and Alt-H respectively. Any of these move focus to the menu. BTW, F10 is another key that sends focus to the menu. Once there the user can press the underscored letter corresponding to desired command. As an example, for New Game it's Alt-F -> N. Or the user can traverse the menu with arrow keys and press the Enter key. The potential conflict is only with the three Alt codes. It does get interesting because the three Alt codes change from language to language. The German word for Tools is Werkzeuge, so Alt-W would make a lot of sense. But Alt-W is the Begin log file keycode unless a module designer explicitly changes it. This means that certain letters are off limits and annoyed German users have to use some less obvious letter. Alt-S is the server control window putting it off limits too. Both of these are configurable in the Global Options, but it probably is best to avoid the default settings. Buttons on the toolbar take precedence over the menu. You get solely the toolbar action and not both (i.e. not the menu). If a counter(s) has focus, it takes precedence over the toolbar buttons. In regards to control codes, the Module Editor has always had these defined. There is nothing new here for control codes. I just pointed out the conflict with Save As and the resolution. |
OK, thanks for clarifying. That certainly calms my nerves a bit 😃 On the other hand, it means to reach, say - Save Game one would need the key sequence
As noted elsewhere, I find translating the key a bit odd. At least for Danish. Most Danes are quite comfortable with using Yours, |
That's interesting. Shows how little I know. The File menu in the Player Module is the longest menu and often with repeat wording. I put the S on Afslut logfil since the A was already taken by Afslut. Nothing saying one can't reuse the same letter, maybe for save and save as, but not dissimilar actions like save log file and quit. If the chosen shortcut key (letter) is not in the word there is no visible cue to the end user. S can work for Gem since it's followed with Spil as in Gem Spil. No easy choices here. Tools menu isn't much better with three Load commands. You are welcome to edit the properties file to your liking. |
My issue is not so much with the choice of letter - clearly there will be some overlaps to sort out. My issue is using translations of the key. That, I believe is wholly unexpected by most users - even if their language of choice isn't English. For example, a Danish user would expect the key To be more explicit Module mananger
Player
In short, do not pay any attention to the translated menu entry text when assigning a letter to a menu entry, but use the same letter irrespective of the choice of language by the user. That, I believe, is what most users will expect. Yours, |
|
On MacOS I see nothing different. Is the change restricted to Windows ? |
No, should work with Mac too. On the Module Manager, the first character of every File menu entry should be underlined. On Windows it depends on how the menu is opened. Mac might be the same. Use the keyboard to open the menu, Alt-F or whatever is the equivalent for Alt on the Mac. When clicking on 'File' with the mouse the underscores are not shown. Does Alt-F Q close the Module Manager? If so then it is working. On Linux the underscores are present regardless. The appearance on each O/S may be affected by the look and feel? I'm not sure. |
I tried Alt-F (Option-F on Mac) etc and it does nothing. I have a feeling that MacOS does not deal with shortcuts in this way. My "research" seems to confirm that. |
|
@riverwanderer Sorry, novice mistake assuming that Java UI controls work more or less the same across operating systems. Got on a Mac briefly and noticed that it somewhat already supports shortcut keys. From Apple support:
The point to note is "type the menu item's name to jump to that item". In effect the first letter of the menu item is the shortcut key once the menu has focus. The Control-F2 equivalent on Windows is F10. @cholmcc The latest commit modifies the Danish menu to follow your suggested shortcut keys. For English, I did not change any of the existing shortcuts. Redefining the few pre-existing shortcuts would be unkind to end users. Below is a list of differences between English and Danish shortcut keys. All the others are the same for both languages. The three criteria for the English shortcuts are:
The menu items identify the shortcut with an underscore. This works fine for English since the shortcut letter always matches some letter in one of the words. This presents a visual cue for the end user. A translated menu item may not have the equivalent letter, thus with nothing underlined it falsely signifies an unassigned shortcut (see Luk spil in the figure). I can see being consistent with common operating system commands like File->New, but not so much with Vassal specific commands. I've also added the accelerator keys to the menu as shown below in the red box. Unsure if these are visible on the Mac. These are the keycodes as defined in General Options.
|
How did the menu receive the focus? Did you press F10 or press and hold the Alt key? I am seeing that the underline is present when the menu receives focus through a keyboard command. Using the mouse, the underline is not shown but the shortcut keys still work as the menu has the focus. Pressing the Alt key after clicking on the menu with the mouse also turns on the underline. The dropdown list is not updated until refreshed by moving to another menu item and back again. The underline is not always shown being dependent on how the user navigates the menu (and the Look'n'Feel). |
…nguages Prefer not to change existing shortcuts that users may be accustomed to. Where possible try to limit top level player menu to Alt-F, Alt-T and Alt-H in order to minimize masking by toolbar buttons.
|
My understanding of the dynamic nature of the underscore is basically a compromise between asethetics and accessibility. Mouse users don't care to see them. They do assist keyboard users with speedier navigation than with arrow keys alone. The behaviour is not limited to Swing or any particular look and feel, VSCode on Windows works the same way. Since MacOS completely disregards the shortcut keys instead using the first letters of the menu item, for greater cross-platform commonality the best shortcut key would be the first letter of each menu item. But, any pre-existing shortcuts should remain unchanged as much as possible. I have compared the latest release with this PR and reverted some of my earlier changes. @cholmcc Are you considering any modifications to the Danish shortcuts? I can update shortcuts as you see fit. |
|
Taking the shortcut key table a step further, this is the output of a PowerShell script of all shortcut keys defined by this PR within the resource files by language. A blank entry indicates no override for that language deferring back to the English default. An asterisk indicates a hidden shortcut key. The shortcut key is active but not readily apparent to the user since the menu text does not contain an instance of that letter. Ideally there should not be any asterisks in this table. Looking for some assistance in nailing down reasonable and intuitive shortcuts. Updated: 2026/02/28 (update 2)
|
Note, my initial objection was to hotkey short-cuts - e.g., a key like Module mananger
Player
However, I still find it problematic to add these mnemonic keys when
Yours, |
The property is not used being replaced by load continuation.
|
Updated the Danish translation file. These are the outstanding issues as far as I can tell.
The Vassal resource files use the term shortcut, so for source code consistency I kept with the same wording. I will edit my earlier post and update the table. |
Hot-keys should not be translated - that would be totally unexpected to most users - not just Danish users. For example, Tools in German is Werkzeuge, but I sincerely believe German users would be surprised if the hot-key is Just dawned on my that I hadn't translated the menu headings:
Right. My bad.
Take the first letter if there's no conflict.
The proper translation of options is valg - not indstillinger. Indstillinger is more like Settings or perhaps Preferences.
You have: translated from I suggest (Auto-translators often f**k up sentence structure, which is somewhat different between Danish and English - despite English being closely related to Danish and Norse - Denmark did, after all, rule England, and William the Conqueror's claim to the English thrown came from his Danish ancestry - albeit a somewhat strained linage 😄 )
OK.
OK. Yours, |
Change Load Log, Fast Forward & Append shortcut to "L" Ensure all shortcuts are uppercase (for consistency only). Rephrase Danish language load continuation informational message.
|
I've made all the changes including updating Scenarie valg. Replaced the load continuation informational message with the new text. I leave it to someone more qualified to resolve any inconsistencies in messaging between valg and indstillinger, and Åben and Indlæs. Changed the default shortcut for Load Log, Fast Forward & Append to "L" from "A". Using "A", the underscore is hard to see as the first occurrence receives the underscore which happens to be the lowercase "a" in "Load". In contrast, the "L" in load has greater visibility. |









Add keyboard shortcuts to the Module Manager, Editor and the Player windows. The shortcut keys are language specific and are defined in the language resource files. The English and all European languages have shortcut keys assigned. This was an interesting exercise in increasing my gaming vocabulary.
I welcome native language speakers to chime in on the language specific shortcut key assignments. Almost undoubtedly there are predefined shortcut keys for the typical operating system commands that I am not aware of. My attempt here is to make shortcut keys unique per sub-menu.
In the Editor, hotkeys are not assigned since most of the editor commands have accelerator keys.
Also in the editor, 'File|Save As' had been given the control-A accelerator key. This is the 'Select All' command which is intercepted by the edit controls. Only if the menu has focus does the control-A accelerator key work as a Save-As. This somewhat defeats the purpose of having an accelerator key. Changing Save-As to
shift-control-Smakes Save-As available just like control-S for File|Save.Toolbar buttons have precedence over menus. For example if a module uses Alt-F for an Action Button, then the File menu for the English language (and some others) will not open. F10 would if it is not also reassigned. Shortcut keys can be useful but they can be masked by modules.