GetGadgetText for ShortcutGadget

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

GetGadgetText for ShortcutGadget

Post 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!
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: GetGadgetText for ShortcutGadget

Post 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
Image
Image
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: GetGadgetText for ShortcutGadget

Post by Dude »

RSBasic, thanks... but it doesn't return Shift+Ctrl+Alt+T correctly. It shows Shift+Strg+A (it's missing Alt).
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: GetGadgetText for ShortcutGadget

Post 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)?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: GetGadgetText for ShortcutGadget

Post by Dude »

forumuser wrote:

Code: Select all

string.s{12}
set it to 16 and try again?
Yep, that works. Thanks! :)
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: GetGadgetText for ShortcutGadget

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