Page 1 of 1

Mac shortcuts (b4)

Posted: Sun Nov 02, 2025 12:42 pm
by Piero
Well, I think this can be considered as a trivial bug report, but maybe it can help:

I always had "Help" assigned to ⌥/ (US keyboard) and it was showing as:
⌥D on menu (totally wrong)
⌥-divide (or something like that; correct and more descriptive) on PB prefs

Now I don't see anything on menu, and on PB prefs I just see: "Alt+"
(All works; I also tried to reassign to see if it crashes…)

Tested on sequoia; is it the same on tahoe?

Re: Mac shortcuts (b4)

Posted: Sun Nov 02, 2025 4:05 pm
by mrbungle
I had an issue since 6.00 where placing keyboard shortcuts in the menu bar get truncated, so i wrote a macro to fix it. perhaps this will help:

Code: Select all

Macro MenuKey(sk)
	If Len(sk) = 1
		sk = InsertString(sk, "+", 1)
	ElseIf Len(sk) = 2
		sk = InsertString(sk, "+", 1)
		sk = InsertString(sk, "+", 2)
	ElseIf Len(sk) = 3
		sk = InsertString(sk, "+", 1)
	    sk = InsertString(sk, "+", 2)
	    sk = InsertString(sk, "+", 4)
	ElseIf Len(sk) = 4
		sk = InsertString(sk, "+", 1)
	    sk = InsertString(sk, "+", 2)
	    sk = InsertString(sk, "+", 4)
	    sk = InsertString(sk, "+", 6)
	EndIf
	
	  sk = ReplaceString(sk, "⇧", "Shift")
	  sk = ReplaceString(sk, "⌘", "Cmd")
	  sk = ReplaceString(sk, "⌥", "Alt")
	  sk = ReplaceString(sk, "⌃", "Ctrl")
EndMacro
sk is a string. It does a replacement, that seems to handle the shortcuts properly.

Re: Mac shortcuts (b4)

Posted: Sun Nov 02, 2025 4:45 pm
by Piero
Thanks mrbungle!

I was talking about IDE problems, but who knows?

Hope this will help Fred & C

Posted: Sat Nov 08, 2025 4:55 pm
by Piero
Produces the "unshifted" key, for "strange" shortcuts…

Code: Select all

ImportC ""
   sel_registerName(str.p-ascii)
   class_addMethod(class, selector, imp, types.p-ascii)
EndImport

Procedure.s modifierFlagsInfo(modifierFlags)
   Protected r1.s
   If modifierFlags & #NSControlKeyMask
      r1 + "⌃"
   EndIf
   If modifierFlags & #NSAlternateKeyMask
      r1 + "⌥"
   EndIf
   If modifierFlags & #NSShiftKeyMask
      r1 + "⇧"
   EndIf
   If modifierFlags & #NSCommandKeyMask
      r1 + "⌘"
   EndIf
   ProcedureReturn r1
EndProcedure

ProcedureC PerformKeyEquivalent(Sender, sel, currentevent)
   Protected modifiers, FlagsInfo.s, Long
   If currentEvent
      Select CocoaMessage(0, currentEvent, "type")
         Case #NSKeyDown
            modifiers = (CocoaMessage(0, currentEvent, "modifierFlags"))
            ;Debug "Key Code: " + CocoaMessage(0, currentEvent, "keyCode")
            Long = CocoaMessage(0, currentEvent, "charactersByApplyingModifiers:")
            CocoaMessage(@Long, Long, "UTF8String")
            FlagsInfo = modifierFlagsInfo(modifiers)
            If FlagsInfo and FlagsInfo <> "⇧"
               Debug "Shortcut: " +FlagsInfo+ UCase(PeekS(Long, -1, #PB_UTF8))
            EndIf
      EndSelect
   EndIf
   ProcedureReturn 1
EndProcedure

OpenWindow(0, 100, 100, 300, 200, "Shortcut Test")

Define class = CocoaMessage(0, WindowID(0), "class")
Define selector = sel_registerName("performKeyEquivalent:") 
class_addMethod(class, selector, @PerformKeyEquivalent(), "v@:@")

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow