MenuItem and Shortcuts

Mac OSX specific forum
jamirokwai
Enthusiast
Enthusiast
Posts: 798
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

MenuItem and Shortcuts

Post 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 :-)
Regards,
JamiroKwai
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: MenuItem and Shortcuts

Post by WilliamL »

It's always worked for me. :D Not having windows I thought it was supposed to work that way.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
jamirokwai
Enthusiast
Enthusiast
Posts: 798
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: MenuItem and Shortcuts

Post 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!?
Regards,
JamiroKwai
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: MenuItem and Shortcuts

Post 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.
quidquid Latine dictum sit altum videtur
jamirokwai
Enthusiast
Enthusiast
Posts: 798
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: MenuItem and Shortcuts

Post 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.
Regards,
JamiroKwai
User avatar
tarmsaft
User
User
Posts: 37
Joined: Sat Jun 30, 2007 12:03 pm
Location: San Francisco

Re: MenuItem and Shortcuts

Post 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.
MacBook Pro (model 7,1) - 2.4GHz Intel Core 2 Duo 4GB - OS X 10.7 Lion.
PB 4.60 RC1
Post Reply