Shortcut name from number

Share your advanced PureBasic knowledge/code with the community.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Shortcut name from number

Post by Trond »

Code updated For 5.20+

Code: Select all

    Procedure.s KeyName(Key.b)
      Ret.s
      Select Key
        Case #PB_Shortcut_Add
          Ret = "Add"
        Case #PB_Shortcut_Back
          Ret = "Backspace"
        Case #PB_Shortcut_Tab
          Ret = "Tab"
        Case #PB_Shortcut_Return
          Ret = "Enter"
        Case #PB_Shortcut_Menu
          Ret = "Context menu"
        Case #PB_Shortcut_Pause
          Ret = "Pause"
        Case #PB_Shortcut_Print
          Ret = "Print Screen"
        Case #PB_Shortcut_Capital
          Ret = "Caps Lock"
        Case #PB_Shortcut_Escape
          Ret = "Escape"
        Case #PB_Shortcut_Space
          Ret = "Space"
        Case #PB_Shortcut_PageUp
          Ret = "Page Up"
        Case #PB_Shortcut_PageDown
          Ret = "Page Down"
        Case #PB_Shortcut_End
          Ret = "End"
        Case #PB_Shortcut_Home
          Ret = "Home"
        Case #PB_Shortcut_Left
          Ret = "Left arrow"
        Case #PB_Shortcut_Up
          Ret = "Up arrow"
        Case #PB_Shortcut_Right
          Ret = "Right arrow"
        Case #PB_Shortcut_Down
          Ret = "Down arrow"
        Case #PB_Shortcut_Select
          Ret = "Select"
        Case #PB_Shortcut_Insert
          Ret = "Insert"
        Case #PB_Shortcut_Delete
          Ret = "Delete"
        Default
          If Key >= #PB_Shortcut_F1 And Key <= #PB_Shortcut_F24
            Ret = "F" + Str(Key - #PB_Shortcut_F1 + 1)
          Else
            Ret = Chr(Key)
          EndIf
      EndSelect
      ProcedureReturn Ret
    EndProcedure


    Procedure.s ShortcutName(Sc)
      Name.s
      Ctrl.s
      Alt.s
      Shift.s
      Char.s
      Char.s = KeyName(sc)
      If (sc / #PB_Shortcut_Control) % 2
        Ctrl = "Ctrl+"
      EndIf
      If sc / #PB_Shortcut_Alt
        Alt = "Alt+"
      EndIf
      If (sc / #PB_Shortcut_Shift) % 2
        Shift = "Shift+"
      EndIf
      Name.s = Ctrl + Alt + Shift + Char
      ProcedureReturn Name
    EndProcedure

    Debug ShortcutName(#PB_Shortcut_Add)
    Debug ShortcutName(#PB_Shortcut_F2 | #PB_Shortcut_Control)
    Debug ShortcutName(#PB_Shortcut_0 | #PB_Shortcut_Control)
    Debug ShortcutName(#PB_Shortcut_B | #PB_Shortcut_Alt)
    Debug ShortcutName(#PB_Shortcut_C | #PB_Shortcut_Shift)
    Debug ShortcutName(#PB_Shortcut_D | #PB_Shortcut_Control | #PB_Shortcut_Alt)
    Debug ShortcutName(#PB_Shortcut_E | #PB_Shortcut_Control | #PB_Shortcut_Shift)
    Debug ShortcutName(#PB_Shortcut_F | #PB_Shortcut_Alt     | #PB_Shortcut_Shift)
    Debug ShortcutName(#PB_Shortcut_G | #PB_Shortcut_Control | #PB_Shortcut_Alt | #PB_Shortcut_Shift)