Underlined keys on gadgets

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Underlined keys on gadgets

Post by BarryG »

In this example, I assumed pressing Alt+[Letter] would select the gadget with that underlined letter? It works like this for menus that are underlined, but not gadgets? If not, what's the point of the underline?

Asking because I've a user make a request for me to add better accessibility to my app, and I thought I could do this as a starting point.

Code: Select all

If OpenWindow(0, 300, 200, 270, 170, "Shortcuts", #PB_Window_SystemMenu)
  CheckBoxGadget(0, 10, 10, 250, 25, "&CheckBox")
  ButtonGadget(1, 10, 50, 250, 25, "&Button")
  PanelGadget(2, 10, 90, 250, 70)
  AddGadgetItem(2, -1, "&One")
  AddGadgetItem(2, -1, "&Two")
  CloseGadgetList()
  SetActiveGadget(0)
  Repeat
    ev = WaitWindowEvent()
  Until ev = #PB_Event_CloseWindow
EndIf
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Underlined keys on gadgets

Post by idle »

This works

Code: Select all

Procedure MySetActiveGadget()
  Protected k 
  For k = 65 To 90
    If GetAsyncKeyState_(k) & $8000 
      keybd_event_(k, 0, 0, 0)
      keybd_event_(k, 0,#KEYEVENTF_KEYUP, 0)  
      If GetAsyncKeyState_(#VK_LMENU) & $8000 Or GetAsyncKeyState_(#VK_RMENU) & $8000
        
        Select UCase(Chr(k))    
          Case "C"
            SetActiveGadget(0)  
          Case "B"
            SetActiveGadget(1)
          Case "O"
            SetActiveGadget(2)
            SetGadgetState(2,0) 
          Case "T"  
            SetActiveGadget(2)
            SetGadgetState(2,1)  
        EndSelect    
      EndIf
    EndIf 
  Next
  
EndProcedure   

If OpenWindow(0, 300, 200, 270, 170, "Shortcuts", #PB_Window_SystemMenu)
  CheckBoxGadget(0, 10, 10, 250, 25, "&CheckBox")
  ButtonGadget(1, 10, 50, 250, 25, "&Button")
  PanelGadget(2, 10, 90, 250, 70)
  AddGadgetItem(2, -1, "&One")
  AddGadgetItem(2, -1, "&Two")
  CloseGadgetList()
    
  SetActiveGadget(0)
  Repeat
    ev = WaitWindowEvent()
    If ev 
     MySetActiveGadget() 
    EndIf   
  Until ev = #PB_Event_CloseWindow
EndIf
User avatar
TI-994A
Addict
Addict
Posts: 2751
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Underlined keys on gadgets

Post by TI-994A »

BarryG wrote: Sun Sep 29, 2024 4:43 am...pressing Alt+[Letter] would select the gadget with that underlined letter?

It should be noted that selection through the ALT key combinations is exclusively a Windows menu feature. However, here is a cross-platform PureBasic emulation of that feature working with other gadgets as well:

Code: Select all

Enumeration
  #window
  #checkbox = 0
  #button
  #panel
  #panelTab1
  #panelTab2
EndEnumeration

checkBox.s = "Checkbox"
button.s = "Button"
panel1.s = "One"
panel2.s = "Two"

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  checkbox = "&" + checkbox
  button = "&" + button
  panel1 = "&" + panel1
  panel2 = "&" + panel2  
CompilerEndIf

If OpenWindow(#window, 300, 200, 270, 170, "Shortcuts", #PB_Window_SystemMenu)
  CheckBoxGadget(#checkbox, 10, 10, 250, 25, checkBox)
  ButtonGadget(#button, 10, 50, 250, 25, button)
  PanelGadget(#panel, 10, 90, 250, 70)
  AddGadgetItem(#panel, -1, panel1)
  AddGadgetItem(#panel, -1, panel2)
  CloseGadgetList()
  SetActiveGadget(#checkbox)
  
  AddKeyboardShortcut(#window, #PB_Shortcut_Alt | #PB_Shortcut_B, #button)
  AddKeyboardShortcut(#window, #PB_Shortcut_Alt | #PB_Shortcut_C, #checkbox)
  AddKeyboardShortcut(#window, #PB_Shortcut_Alt | #PB_Shortcut_O, #panelTab1)
  AddKeyboardShortcut(#window, #PB_Shortcut_Alt | #PB_Shortcut_T, #panelTab2)
  
  Repeat
    ev = WaitWindowEvent()
    Select ev
        
      Case #PB_Event_Menu
        Select EventMenu()            
          Case #button
            PostEvent(#PB_Event_Gadget, #window, #button)
          Case #checkbox            
            kbAction = #True
            PostEvent(#PB_Event_Gadget, #window, #checkbox)
          Case #panelTab1
            kbAction = #panelTab1
            PostEvent(#PB_Event_Gadget, #window, #panel)
          Case #panelTab2
            kbAction = #panelTab2
            PostEvent(#PB_Event_Gadget, #window, #panel)            
        EndSelect
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #button
            MessageRequester("Keyboard Shortcuts", "Button clicked!")
          Case #checkbox
            If kbAction
              kbAction = #False
              SetGadgetState(#checkbox, GetGadgetState(#checkbox) ! 1)
            EndIf            
          Case #panel
            If kbAction              
              If kbAction = #panelTab1
                SetGadgetState(#panel, 0)
              Else
                SetGadgetState(#panel, 1)
              EndIf
              kbAction = #False
            EndIf            
        EndSelect       
        
    EndSelect    
    
  Until ev = #PB_Event_CloseWindow  
EndIf

Since the ampersand (&) characters will not be automatically obfuscated in macOS or Linux, it might be best to omit them for those platforms.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Underlined keys on gadgets

Post by RASHAD »

For Windows

Code: Select all

If OpenWindow(0, 300, 200, 270, 170, "Shortcuts", #PB_Window_SystemMenu) 
  CheckBoxGadget(0, 10, 10, 250, 25, "&CheckBox")
  ButtonGadget(1, 10, 50, 250, 25, "&Button")
  PanelGadget(2, 10, 90, 250, 70)
  AddGadgetItem(2, -1, "&One")
  AddGadgetItem(2, -1, "&Two")
  CloseGadgetList()
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #WM_SYSKEYDOWN
        Select EventwParam()
          Case 67
            SetGadgetState(0,GetGadgetState(0) ! 1 )            
            SetActiveGadget(0)
          Case 66
            SetActiveGadget(1)
            ;OpenFileRequester("", "", "", 0)            
          Case 79
            SetActiveGadget(2)
            SetGadgetState(2,0)
          Case 84
            SetActiveGadget(2)
            SetGadgetState(2,1)
        EndSelect
    EndSelect            
  Until Quit = 1
EndIf

Egypt my love
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: Underlined keys on gadgets

Post by PBJim »

TI-994A wrote: Sun Sep 29, 2024 7:10 am It should be noted that selection through the ALT key combinations is exclusively a Windows menu feature.
Alt-key shortcuts within buttons are in fact supported by Windows, as this article explains. In VB and C# the convention of adding the ampersand to all buttons is encouraged. Nothing further is required. It's just that PureBasic implements this AddKeyboardShortcut() function via menu events.

https://learn.microsoft.com/en-us/dotne ... esktop-8.0
User avatar
TI-994A
Addict
Addict
Posts: 2751
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Underlined keys on gadgets

Post by TI-994A »

PBJim wrote: Sun Sep 29, 2024 8:39 amAlt-key shortcuts within buttons are in fact supported by Windows, as this article explains. In VB and C# the convention of adding the ampersand to all buttons is encouraged. Nothing further is required. It's just that PureBasic implements this AddKeyboardShortcut() function via menu events.

Not quite. The AddKeyboardShortcut() function simply adds a secondary trigger but does not handle the gadget in any way. Case in point:

Code: Select all

OpenWindow(0, 0, 0, 300, 150, "AddKeyboardShortcut Example", 
           #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CheckBoxGadget(0, 10, 10, 250, 30, "Checkkbox")
AddKeyboardShortcut(0, #PB_Shortcut_Alt | #PB_Shortcut_C, 0)

Repeat 
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = #True
    Case #PB_Event_Menu
      Select EventMenu()            
        Case 0
          Debug "shortcut triggered but checkbox state not changed!"
      EndSelect
  EndSelect
Until appQuit

In VB and C#, access keys trigger the gadgets (controls) directly.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Underlined keys on gadgets

Post by BarryG »

I was hoping it would be automatic when adding "&" to the text, but obviously not. But the user replied to me email with this:

Image

The link he gave me -> https://learn.microsoft.com/en-us/windo ... ndows-apps

I don't think I'm going to able to do what he asks. :( Especially since clicking a PanelGadget tab will then automatically set the focus to a gadget inside that tab, etc.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Underlined keys on gadgets

Post by idle »

following on from Ti-994A

This might have some legs as in easy to retrofit but needs some additional thoughts
it's limited to 256 gadgets and 256 items

Code: Select all


Procedure MenuSetActiveGadget() 
  Protected gadget,item 
  
  gadget = EventMenu() >> 8 
  
  item = EventMenu() & $FF 
  
  SetActiveGadget(gadget)
  If item  
    SetGadgetState(gadget,item-1)   
  EndIf   
EndProcedure  

Procedure.s SC(window,shortcut.s,gad,item=0) 
  Protected  key.s,pos,gadget  
  pos = FindString(ShortCut,"&") 
  If pos 
    key=UCase(Mid(ShortCut,pos+1,1)) 
    gadget = (gad << 8) | (item+1)
    Select key 
      Case "A"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_A, gadget)
      Case "B"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_B, gadget)  
      Case "C"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_C, gadget)
      Case "D"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_D, gadget)
      Case "E"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_E, gadget)
      Case "F"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_F, gadget)
      Case "G"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_G, gadget)
      Case "H" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_H, gadget)
      Case "I" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_I, gadget)
      Case "J" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_J, gadget)
      Case "K" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_K, gadget)
      Case "L" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_L, gadget)
      Case "M" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_M, gadget)
      Case "N" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_N, gadget)
      Case "O" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_O, gadget)
      Case "P" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_P, gadget)
      Case "Q" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_Q, gadget)
      Case "R" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_R, gadget)
      Case "S" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_S, gadget)
      Case "T" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_T, gadget)
      Case "U" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_U, gadget)
      Case "V" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_V, gadget)
      Case "W" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_W, gadget)
      Case "X" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_X, gadget)
      Case "Y" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_Y, gadget)
      Case "Z" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_Z, gadget)
    EndSelect
    
    CreateMenu(window, WindowID(window))
    BindMenuEvent(window,gadget,@MenuSetActiveGadget()) 
    
  EndIf 
  
  ProcedureReturn shortcut
  
EndProcedure  

If OpenWindow(0, 300, 200, 270, 170, "Shortcuts", #PB_Window_SystemMenu)
  CheckBoxGadget(0, 10, 10, 250, 25, sc(0,"&CheckBox",0))
  ButtonGadget(1, 10, 50, 250, 25, sc(0,"&Button",1))
  PanelGadget(2, 10, 90, 250, 70)
  AddGadgetItem(2, -1, sc(0,"&One",2,0))
  AddGadgetItem(2, -1, sc(0,"&Two",2,1))
  CloseGadgetList()
  
  SetActiveGadget(0)
  Repeat
    ev = WaitWindowEvent()
  Until ev = #PB_Event_CloseWindow
EndIf

Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Underlined keys on gadgets

Post by Quin »

I asked Fred about this a while ago, and according to him this can be done with a flag to the window creation that has yet to be added.
User avatar
TI-994A
Addict
Addict
Posts: 2751
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Underlined keys on gadgets

Post by TI-994A »

BarryG wrote: Sun Sep 29, 2024 10:09 amI was hoping it would be automatic when adding "&" to the text...
That would require automatic event-linking. A feature request, perhaps. :lol:

BarryG wrote: Sun Sep 29, 2024 10:09 am...clicking a PanelGadget tab will then automatically set the focus to a gadget inside that tab, etc.
It could be viable with some custom tab ordering:

Code: Select all

Enumeration
  #window
  #checkbox = 0
  #button
  #panel
  #panelTab1
  #panelTab2
  #p1Button1
  #p1Button2
  #p2Button1
  #p2Button2
  #tabOrder
EndEnumeration

checkBox.s = "Selector"
button.s = "Launch"
panel1.s = "Panel 1"
panel2.s = "Panel 2"

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  checkbox = "&" + checkbox
  button = "&" + button
  panel1 = "&" + panel1
  panel2 = "&" + panel2  
CompilerEndIf

If OpenWindow(#window, 300, 200, 270, 200, "Shortcuts", #PB_Window_SystemMenu)
  CheckBoxGadget(#checkbox, 10, 10, 250, 25, checkBox)
  ButtonGadget(#button, 10, 50, 250, 25, button)
  PanelGadget(#panel, 10, 90, 250, 100)
  AddGadgetItem(#panel, -1, panel1)
  ButtonGadget(#p1Button1, 40, 5, 150, 24,"First Action")
  ButtonGadget(#p1Button2, 40, 30, 150, 24,"Second Action")
  AddGadgetItem(#panel, -1, panel2)
  ButtonGadget(#p2Button1, 40, 5, 150, 24,"First Task")
  ButtonGadget(#p2Button2, 40, 30, 150, 24,"Second Task")
  CloseGadgetList()
  SetActiveGadget(#checkbox)
  
  AddKeyboardShortcut(#window, #PB_Shortcut_Alt | #PB_Shortcut_B, #button)
  AddKeyboardShortcut(#window, #PB_Shortcut_Alt | #PB_Shortcut_C, #checkbox)
  AddKeyboardShortcut(#window, #PB_Shortcut_Alt | #PB_Shortcut_O, #panelTab1)
  AddKeyboardShortcut(#window, #PB_Shortcut_Alt | #PB_Shortcut_T, #panelTab2)
  AddKeyboardShortcut(#window, #PB_Shortcut_Tab, #tabOrder)
  
  SetGadgetData(#checkbox, #button)
  SetGadgetData(#button, #panel)
  SetGadgetData(#panel, #p1Button1)  
  SetGadgetData(#p1Button1, #p1Button2)  
  SetGadgetData(#p1Button2, #panel)
  SetGadgetData(#p2Button1, #p2Button2)  
  SetGadgetData(#p2Button2, #checkbox)  
  
  Repeat
    ev = WaitWindowEvent()
    Select ev
        
      Case #PB_Event_Menu
        Select EventMenu()            
          Case #button
            PostEvent(#PB_Event_Gadget, #window, #button)
          Case #checkbox            
            kbAction = #True
            PostEvent(#PB_Event_Gadget, #window, #checkbox)
          Case #panelTab1
            kbAction = #panelTab1
            PostEvent(#PB_Event_Gadget, #window, #panel)
          Case #panelTab2
            kbAction = #panelTab2
            PostEvent(#PB_Event_Gadget, #window, #panel)    
          Case #tabOrder
            currentGadget = GetActiveGadget()
            nextGadget = GetGadgetData(currentGadget)                        
            If currentGadget = #p1Button2            
              SetGadgetState(#panel, 1)              
            EndIf                
            If currentGadget = #panel And GetGadgetState(#panel) = 1
              nextGadget = #p2Button1
            EndIf            
            If currentGadget = #p2Button2
              SetGadgetState(#panel, 0)
            EndIf            
            SetActiveGadget(nextGadget)                
        EndSelect
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #button
            MessageRequester("Keyboard Shortcuts", "Button clicked!")
          Case #checkbox
            If kbAction
              kbAction = #False
              SetGadgetState(#checkbox, GetGadgetState(#checkbox) ! 1)
            EndIf            
          Case #panel
            If kbAction              
              If kbAction = #panelTab1
                SetGadgetState(#panel, 0)
              Else
                SetGadgetState(#panel, 1)
              EndIf
              kbAction = #False
            EndIf            
        EndSelect       
        
    EndSelect    
    
  Until ev = #PB_Event_CloseWindow  
EndIf

Seems to work well with VoiceOver on macOS.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Underlined keys on gadgets

Post by idle »

BarryG wrote: Sun Sep 29, 2024 10:09 am I don't think I'm going to able to do what he asks. :( Especially since clicking a PanelGadget tab will then automatically set the focus to a gadget inside that tab, etc.
it doesn't appear to automatically set the focus to gadgets contained in a tab here
This should be easy to retrofit

SC(window,shortcut.s,gadget,gadgetitem=0)

Code: Select all


Procedure MenuSetActiveGadget() 
  Protected gadget,item 
  gadget = EventMenu() >> 8 
  item = EventMenu() & $FF 
  SetActiveGadget(gadget)
  If item  
    SetGadgetState(gadget,item-1)   
  EndIf   
EndProcedure  

Procedure.s SC(window,shortcut.s,gad,item=0) 
  Protected  key.s,pos,gadget  
  pos = FindString(ShortCut,"&") 
  If pos 
    key=UCase(Mid(ShortCut,pos+1,1)) 
    gadget = (gad << 8) | (item+1)
    Select key 
      Case "A"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_A, gadget)
      Case "B"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_B, gadget)  
      Case "C"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_C, gadget)
      Case "D"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_D, gadget)
      Case "E"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_E, gadget)
      Case "F"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_F, gadget)
      Case "G"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_G, gadget)
      Case "H" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_H, gadget)
      Case "I" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_I, gadget)
      Case "J" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_J, gadget)
      Case "K" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_K, gadget)
      Case "L" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_L, gadget)
      Case "M" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_M, gadget)
      Case "N" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_N, gadget)
      Case "O" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_O, gadget)
      Case "P" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_P, gadget)
      Case "Q" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_Q, gadget)
      Case "R" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_R, gadget)
      Case "S" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_S, gadget)
      Case "T" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_T, gadget)
      Case "U" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_U, gadget)
      Case "V" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_V, gadget)
      Case "W" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_W, gadget)
      Case "X" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_X, gadget)
      Case "Y" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_Y, gadget)
      Case "Z" 
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_Z, gadget)
      Case "1"
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_1, gadget)  
      Case "2"  
        AddKeyboardShortcut(window, #PB_Shortcut_Alt | #PB_Shortcut_2, gadget)
    EndSelect
    
    CreateMenu(window, WindowID(window))
    BindMenuEvent(window,gadget,@MenuSetActiveGadget()) 
    
  EndIf 
  
  ProcedureReturn shortcut
  
EndProcedure  

If OpenWindow(0, 300, 200, 270, 170, "Shortcuts", #PB_Window_SystemMenu)
  CheckBoxGadget(0, 10, 10, 250, 25, sc(0,"&CheckBox",0))
  ButtonGadget(1, 10, 50, 250, 25, sc(0,"&Button",1))
  PanelGadget(2, 10, 90, 250, 70)
  AddGadgetItem(2, -1, sc(0,"&One",2,0))
  AddGadgetItem(2, -1, sc(0,"&Two",2,1))
  ButtonGadget(3, 10, 15, 80, 24,sc(0,"Button &1",3))
  ButtonGadget(4, 95, 15, 80, 24,sc(0,"Button &2",4))
  
  CloseGadgetList()
  
  SetActiveGadget(0)
  Repeat
    ev = WaitWindowEvent()
  Until ev = #PB_Event_CloseWindow
EndIf

BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Underlined keys on gadgets

Post by BarryG »

idle wrote: Sun Sep 29, 2024 9:49 pm
BarryG wrote: Sun Sep 29, 2024 10:09 am I don't think I'm going to able to do what he asks. :( Especially since clicking a PanelGadget tab will then automatically set the focus to a gadget inside that tab, etc.
it doesn't appear to automatically set the focus to gadgets contained in a tab here
Sorry: I meant my app is coded by myself to do that, for the user's convenience. Not that PureBasic itself does it.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Underlined keys on gadgets

Post by idle »

BarryG wrote: Sun Sep 29, 2024 9:58 pm
idle wrote: Sun Sep 29, 2024 9:49 pm
BarryG wrote: Sun Sep 29, 2024 10:09 am I don't think I'm going to able to do what he asks. :( Especially since clicking a PanelGadget tab will then automatically set the focus to a gadget inside that tab, etc.
it doesn't appear to automatically set the focus to gadgets contained in a tab here
Sorry: I meant my app is coded by myself to do that, for the user's convenience. Not that PureBasic itself does it.
I've set it so you can access the gadgets in a tab panel. it's limited to 63 gadgets, 31 items, 31 sub gadgets
viewtopic.php?t=85457
Post Reply