GetGadgetText for ShortcutGadget
Posted: Wed Mar 02, 2011 1:33 pm
Returns the actual text like "STRG + A"
http://www.purebasic.com
https://www.purebasic.fr/english/
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