Need wxW Syntax for Two-Step Keyboard Shortcut Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Need wxW Syntax for Two-Step Keyboard Shortcut

Post by ColleenKobe »

Hi! I am creating a menu bar in wxWidgets, using CodeLite. I am having trouble assigning a keyboard shortcut to my Menu Item, and I wonder if someone can help me.

In this menu bar, I have a File menu option, and under that, I have the menu items New, Open, Save, Save As, etc.

I would like to assign the following two-step keyboard shortcuts to these menu items:

Alt-F, N => File, New
Alt-F, O => File, Open
Alt-F, S => File, Save

I have looked online for this but have not found anything that addresses multiple-key keyboard shortcuts.

I do see lots of ways to assign one-step keyboard shortcuts, and putting Alt-F in the wxWidgets "Shortcut" field for the File Menu Item does bring up the File menu. But if I try to add an "O" for the "Open" part, the O is ignored. I have tried "Alt-F,O", "Alt-F;O", and "Alt-F O", and all have failed.

Suggestions?

Software Versions:
------------------
CodeLite: 9.1.5
tdm-gcc: 5.1.0.3
Windows 7: 6.1
wxWidgets: 3.1.0
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Need wxW Syntax for Two-Step Keyboard Shortcut

Post by doublemax »

There are two different mechanics at work here. Keyboard shortcuts are always one command, like Ctrl-O for open and they work even if the file menu is not open.

The fact that ALT-F opens the file menu is a native Windows behavior if the "File" menu is written as "&File". In the same way, just use "&Open" instead of "Open" and you should get the behavior you want.
Use the source, Luke!
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Re: Need wxW Syntax for Two-Step Keyboard Shortcut

Post by ColleenKobe »

doublemax wrote:There are two different mechanics at work here. Keyboard shortcuts are always one command, like Ctrl-O for open and they work even if the file menu is not open.

The fact that ALT-F opens the file menu is a native Windows behavior if the "File" menu is written as "&File". In the same way, just use "&Open" instead of "Open" and you should get the behavior you want.
Yes, I have seen the one-step keyboard shortcut, and I understand it. I was actually looking for the two-step. I want to specifically lead the user to the "File" menu first, and the second letter would be the first letter of the menu item. The reason is that there may be instances where multiple menu items under different headings might start with the same letter. Then one of them has to have a shortcut starting with its second letter, or something, and that just seemed to introduce confusion to me.

To use an example from Microsoft Word: users can press Alt-I, F to Insert a Field code into a document, Alt-I,I to insert a hyperlink, or Alt-V,H to view headers and footers. (Having said that, I know that many old-style keyboard shortcuts still work, such as . But those commands don't appear on any official Microsoft lists of keyboard shortcuts.)

It may be that what I want is impossible, and that would be disappointing but I would use one-character shortcuts like everyone else.
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Need wxW Syntax for Two-Step Keyboard Shortcut

Post by doublemax »

I think you misunderstood me. What you want does already work, all you have to do is to use "&Open" instead of "Open". This will underline the "O" under Windows and the menu entry can be selected by pressing "O" when the menu is open.

Technically it's not a two-step shortcut, it's just the normal Windows way to make menus accessible by keyboard.
Use the source, Luke!
User avatar
T-Rex
Moderator
Moderator
Posts: 1248
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: Need wxW Syntax for Two-Step Keyboard Shortcut

Post by T-Rex »

I think that ColleenKobe's example with Alt is just a special case. Seems that he is asking about the behavior like in Visual Studio when the shortcut Ctrl+K, C comments out the code and Ctrl+K, U uncomments.

2ColleenKobe: indeed, if you want to use the shortcut with Alt for menus, you can just add the & before the character which you want to use with Alt in main menu and then & in a submenu before the second character in your shortcut.

E.g Alt+F, O can be implemented by specifying the label "&File" for the top level menu and then "&Open" for the menu item in a submenu. This is a default system's behavior. For 2-step shortcuts with Ctrl you need to handle them in wxAcceleratorTable or use the native keyboard hook for each platform (which looks like more reasonable/predictable solution for me)
Post Reply