Page 1 of 1

MenuItem and Shortcuts

Posted: Thu Jan 13, 2011 9:40 am
by jamirokwai
Hi board,

is it true, that you don't have to add a keyboard shortcut for every MenuItem on Mac OS?
This works and fires a MenuEvent.

Code: Select all

MenuItem (1,"Info" + Chr(9) + "CMD+I")
Interestingly, I have to add the KeyboardShortcut manually for Windows like this

Code: Select all

MenuItem ( 1, "Info" + Chr(9) + "Ctrl+I")
AddKeyboardShortcut(1,#PB_Shortcut_Control|#PB_Shortcut_I,1)
Is it true, or just bad habit :-)

Re: MenuItem and Shortcuts

Posted: Thu Jan 13, 2011 6:03 pm
by WilliamL
It's always worked for me. :D Not having windows I thought it was supposed to work that way.

Re: MenuItem and Shortcuts

Posted: Thu Jan 13, 2011 10:43 pm
by jamirokwai
WilliamL wrote:It's always worked for me. :D Not having windows I thought it was supposed to work that way.
Hi WilliamL,

that reminds me of thinking the same, when I ran into this.
I was totally puzzled, when Windows misbehaved :P

Maybe the Mac OS-Approach with MenuItem is better!?

Re: MenuItem and Shortcuts

Posted: Thu Jan 13, 2011 11:24 pm
by freak
This is an OSX-only effect.

Basically the only way to put the shortcut symbols into the menu is to actually assign the shortcut to the menu item. It doesn't hurt though if you do it again using AddKeyboardShortcut(), so just do that too and it will work on all platforms.

Re: MenuItem and Shortcuts

Posted: Fri Jan 14, 2011 8:27 am
by jamirokwai
freak wrote:This is an OSX-only effect.

Basically the only way to put the shortcut symbols into the menu is to actually assign the shortcut to the menu item. It doesn't hurt though if you do it again using AddKeyboardShortcut(), so just do that too and it will work on all platforms.
Hi Freak,

just a few lines of extra-code, and my Programs support Menu-Shortcuts on Windows as well. Mac OS is my primary development platform, so at first, I didn't know about the Shortcuts.

Thanks for the info! Helps a lot.

Re: MenuItem and Shortcuts

Posted: Sun Jul 03, 2011 6:41 pm
by tarmsaft
This actually produces an unwanted behaviour when coding and should be treated as a bug.
I have in my menu two items that uses the same shortcut key, simply because I want to be able to toggle fast between them. Obviously, as some of you probably dying to point out I could have only one item and change the label every other time. To make it short, the two item solution is the proper behaviour in the grand scheme of the program.

So, if you have a shortcut that assigns a key, in this case F to all events pertaining to the key, you loose the ability to listen to that event in the event loop. In simpler terms, event 100 is never triggered in the code below when you push F, only 30.

snip----
AddKeyboardShortcut(w()\win, #PB_Shortcut_F, 100)
MenuItem(30, "Full size" + Chr(9) + "F")
MenuItem(31, "Fit largest side to screen" + Chr(9) + "F")
----

If you do the less aesthetically pleasing method of white-spacing (the characters do not always align up well on the right side), it works as it should. I.e. 100 is triggered on a F, and 30 and 31 respectively when you push them in the menu.

snip----
AddKeyboardShortcut(w()\win, #PB_Shortcut_F, 100)
MenuItem(30, "Full size F")
MenuItem(31, "Fit largest side to screen F")
----

If it should not be treated as a bug, please motivate. Could someone otherwise help me move this thread to the bug section.