Mac shortcuts (b4)

Just starting out? Need help? Post your questions and find answers here.
User avatar
Piero
Addict
Addict
Posts: 1128
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Mac shortcuts (b4)

Post 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?
mrbungle
Enthusiast
Enthusiast
Posts: 176
Joined: Wed Dec 30, 2020 3:18 am

Re: Mac shortcuts (b4)

Post 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.
User avatar
Piero
Addict
Addict
Posts: 1128
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Mac shortcuts (b4)

Post by Piero »

Thanks mrbungle!

I was talking about IDE problems, but who knows?
User avatar
Piero
Addict
Addict
Posts: 1128
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Hope this will help Fred & C

Post 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
Post Reply