Page 1 of 1

GetGadgetText for ShortcutGadget

Posted: Sat Sep 22, 2018 6:18 am
by Dude
The ShortcutGadget() was added in 2009 and I only literally just discovered it now! :shock:

However, I see that GetGadgetState() only returns the keycode value for it, so it'd be extra handy if GetGadgetText() returned the actual text in it. After all, any gadget that holds text should have a way of having said text returned. In this case, it would mean we could easily get (for example) "Ctrl +A" without having to code a routine to convert 131137 to "Ctrl + A".

Thanks!

Re: GetGadgetText for ShortcutGadget

Posted: Mon Sep 24, 2018 8:38 am
by RSBasic
+1

Until the function was developed, here is a temporary solution:

Code: Select all

EnableExplicit

;By Wolfram
Procedure.s shortcutToString(SC)
  Protected string.s{12}, modifiyer
 
  modifiyer = SC >>16
  If modifiyer & 1
    string  ="Shift+" 
  EndIf
 
 
  modifiyer >>1
  If modifiyer & 1
    string  +"Strg+" 
  EndIf
 
  modifiyer >>1
  If modifiyer & 1
    string  +"Alt+"   
  EndIf
 
  modifiyer >>1
  If modifiyer & 1
    string  +"Cmd+" 
  EndIf

  string +UCase(Chr(SC & $FFFF))
 
  ProcedureReturn string
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ShortcutGadget(1, 10, 10, 200, 20, 0)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            Debug shortcutToString(GetGadgetState(1))
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf

Re: GetGadgetText for ShortcutGadget

Posted: Mon Sep 24, 2018 8:43 am
by Dude
RSBasic, thanks... but it doesn't return Shift+Ctrl+Alt+T correctly. It shows Shift+Strg+A (it's missing Alt).

Re: GetGadgetText for ShortcutGadget

Posted: Mon Sep 24, 2018 9:40 am
by forumuser

Code: Select all

string.s{12}
set it to 16 and try again

@RSBasic

Cmd = Win key?

Should that key actually work (it has it's normal function, e.g. it calls the start menu when pressed)?

Re: GetGadgetText for ShortcutGadget

Posted: Mon Sep 24, 2018 12:59 pm
by Dude
forumuser wrote:

Code: Select all

string.s{12}
set it to 16 and try again?
Yep, that works. Thanks! :)

Re: GetGadgetText for ShortcutGadget

Posted: Mon Nov 18, 2019 7:23 am
by Rinzwind
GetGadgetText works now right?

Anyway, do you also have a stringToShortcut function laying around?

SetGadgetText(sc, "⌃C")
Debug GetGadgetState(sc)
doesn't work..

Also seems like ShortcutGadget does not send a #PB_Event_Gadget event?