Page 1 of 1

GetGadgetText for ShortcutGadget

Posted: Wed Mar 02, 2011 1:33 pm
by ts-soft
Returns the actual text like "STRG + A"

Re: GetGadgetText for ShortcutGadget

Posted: Wed Mar 02, 2011 2:07 pm
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


Re: GetGadgetText for ShortcutGadget

Posted: Wed Mar 02, 2011 2:19 pm
by c4s
Note the difference between "Strg" in German and "Ctrl" in English. There are a lot other combinations as well.

Re: GetGadgetText for ShortcutGadget

Posted: Wed Mar 02, 2011 2:23 pm
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.

Re: GetGadgetText for ShortcutGadget

Posted: Wed Mar 02, 2011 4:59 pm
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.