GetGadgetText for ShortcutGadget

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

GetGadgetText for ShortcutGadget

Post by ts-soft »

Returns the actual text like "STRG + A"
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: GetGadgetText for ShortcutGadget

Post by Fangbeast »

Code: Select all

;==========================================================================================================================
; Get the text of the associated shortcut constant
;==========================================================================================================================

Procedure.s GetShortcutText(Constant.i)

  ;------------------------------------------------------------------------------------------------
  ; Sroddy code
  ;------------------------------------------------------------------------------------------------

;   Protected ResultString.s
;   If Constant & #PB_Shortcut_Control
;     ResultString.s = "Ctrl +  "
;   EndIf
;   If Constant & #PB_Shortcut_Shift
;     ResultString.s + "Shift + "
;   EndIf
;   If Constant & #PB_Shortcut_Alt
;     ResultString.s + "Alt + "
;   EndIf
;   Constant & ~ (#PB_Shortcut_Shift | #PB_Shortcut_Control | #PB_Shortcut_Alt)
;   Select Constant
;     Case '0' To '9', 'A' To 'Z'
;       ResultString.s + Chr(Constant)
;     Case #PB_Shortcut_F1 To #PB_Shortcut_F24
;       ResultString.s + "F" + Str(Constant - #PB_Shortcut_F1 + 1)
;     Case '~' To '='
;       ResultString.s + Chr(Constant)
;   EndSelect
;   ProcedureReturn ResultString.s

  ;------------------------------------------------------------------------------------------------
  ; NetMaestro 2009. NetMaestro code modded by Sroddy code  ; Unused  mod$, ctrl$, shift$, alt$
  ;------------------------------------------------------------------------------------------------
  ; 
  Protected KeyLocale, VirtualKey, KeyString.s, ResultString.s

  If Constant.i & #PB_Shortcut_Control
    ResultString.s = "Ctrl + "
  EndIf

  If Constant.i & #PB_Shortcut_Shift
    ResultString.s + "Shift + "
  EndIf

  If Constant.i & #PB_Shortcut_Alt
    ResultString.s + "Alt + "
  EndIf

  KeyLocale = GetKeyboardLayout_(GetCurrentThreadId_())

  KeyString.s = Space(100)

  ; Virtual key

  VirtualKey = MapVirtualKeyEx_(Constant.i & $FF, 0, KeyLocale) << 16

  If Constant.i >> 8 & #HOTKEYF_EXT Or (Constant.i & $FF >= #PB_Shortcut_Prior And Constant.i & $FF <= #PB_Shortcut_Down)
    VirtualKey | (1 << 24) ; Set the extended key bit
  EndIf

  GetKeyNameText_(VirtualKey, @KeyString, 100)

  ResultString.s + KeyString.s

  If ResultString.s = ""
    ResultString.s = "None"
  EndIf

  ProcedureReturn ResultString.s

EndProcedure

Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: GetGadgetText for ShortcutGadget

Post by c4s »

Note the difference between "Strg" in German and "Ctrl" in English. There are a lot other combinations as well.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GetGadgetText for ShortcutGadget

Post by ts-soft »

Thx, but doesn't work correct and use API!

Comes Ctrl and not STRG for German, EINGABE (Return) doesn't work,
and with API it is useless for me.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: GetGadgetText for ShortcutGadget

Post by c4s »

I just got the idea that it might be more useful to add a complete new function for this, so we don't have to create a ShortcutGadget() just to get the text of a key combination.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Post Reply