I hope these let you more understand how to filter the events.
In these example you have a normal menu shortcut CMD+S for "save" and CMD+ALT+S for "save as..."
Code: Select all
#NSAlphaShiftKeyMask = 1 << 16
#NSShiftKeyMask = 1 << 17
#NSControlKeyMask = 1 << 18
#NSAlternateKeyMask = 1 << 19
#NSCommandKeyMask = 1 << 20
Global modifier
ProcedureC eventTapFunction(proxy, type, event, refcon)
Protected flags = CGEventGetFlags_(event)
;//Menu item text with ALT key
If flags & #NSAlternateKeyMask
SetMenuItemText(0, 1, "Load..." +#TAB$ +"Alt+CMD+l")
SetMenuItemText(0, 2, "Save As..." +#TAB$ +"Alt+CMD+S")
;//Menu item text normal - without ALT key
Else
SetMenuItemText(0, 1, "Load" +#TAB$ +"CMD+l")
SetMenuItemText(0, 2, "Save" +#TAB$ +"CMD+s")
EndIf
modifier = flags
EndProcedure
If OpenWindow(0, 0, 0, 320, 170, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateMenu(0, WindowID(0))
MenuTitle("File")
; How about an opt+load?
MenuItem(1, "Load" +#TAB$ +"CMD+l")
MenuItem(2, "Save" +#TAB$ +"CMD+s")
EndIf
eventTap = CGEventTapCreate_(0, 0, 1, $1000, @eventTapFunction(), 0)
If eventTap
CocoaMessage(0, CocoaMessage(0, 0, "NSRunLoop currentRunLoop"), "addPort:", eventTap, "forMode:$", @"kCFRunLoopCommonModes")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
;//Menu behavior with ALT key
If modifier & #NSAlternateKeyMask
Select EventMenu()
Case 1
MessageRequester("Info", "Menu with Alt")
Case 2
MessageRequester("Info", "save As...")
EndSelect
;//Menu behavior without ALT key
Else
Select EventMenu()
Case 1
MessageRequester("Info", "Menu without Alt")
Case 2
MessageRequester("Info", "save")
EndSelect
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf