RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Just starting out? Need help? Post your questions and find answers here.
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by ozzie »

If I use RemoveKeyboardShortcut with #PB_Shortcut_All then this prevents the tab key from tabbing between fields.

For example, in this program you cannot tab through the fields unless you comment out 'RemoveKeyboardShortcut(0, #PB_Shortcut_All)':

Code: Select all

If OpenWindow(0, 0, 0, 305, 240, "Shortcut Tab Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(1,100,30,80,20,"1")
  StringGadget(2,100,60,80,20,"2")
  StringGadget(3,100,90,80,20,"3")
  SetActiveGadget(1)

  RemoveKeyboardShortcut(0, #PB_Shortcut_All)
  
  Repeat
    giWindowEvent = WaitWindowEvent()
  Until giWindowEvent = #PB_Event_CloseWindow
EndIf
How can I reinstate normal tab behavior after using RemoveKeyboardShortcut(0, #PB_Shortcut_All)? I guess I could maintain an array of shortcuts I've added by AddKeyboardShortcut() and step through that array and remove each shortcut individually, but if there's an easier way I'd rather use it!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by RASHAD »

Use next snippet instead

Code: Select all

If OpenWindow(0, 0, 0, 305, 240, "Shortcut Tab Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(1,100,30,80,20,"1")
  StringGadget(2,100,60,80,20,"2")
  StringGadget(3,100,90,80,20,"3")
  ButtonGadget(4,10,120,60,20,"TEST")
  SetActiveGadget(1)
  AddKeyboardShortcut(0,#PB_Shortcut_A,10)  
  
  Repeat
   Select WaitWindowEvent()
   Case #PB_Event_CloseWindow
          Quit = 1
          
   Case #PB_Event_Menu
        Select EventMenu()
              Case 10
                 Debug "A"
        EndSelect
        
    Case #PB_Event_Gadget
         Select EventGadget()
              Case 4
                  For i = 0 To 64000
                    If i = 9
                        i + 1
                    EndIf   
                        RemoveKeyboardShortcut(0,i)
                  Next
                  
         EndSelect
    EndSelect
  Until Quit = 1
EndIf
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by netmaestro »

If RemoveKeyboardShortcut with #PB_All is destroying the keyboard accelerators that were in place before any AddKeyboardShortcut commands were executed, then that's a bug in PureBasic. RemoveKeyboardShortcut with #PB_All should restore the accelerator table to the condition it was in before any AddKeyboardShortcut only, no more than that. I recommend reporting this as a bug. Let the dev team worry about skipping over the tab key.
BERESHEIT
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by ozzie »

I thought it might be a bug but wasn't sure. I've now re-posted this in the Bugs forum - so this current topic may be deleted.
PB Fanatic
User
User
Posts: 49
Joined: Wed Dec 17, 2014 11:54 am

Re: RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by PB Fanatic »

Not a bug for the reason I pointed out in your bug report.
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by ozzie »

OK - I've just noticed that under AddKeyboardShortcut() in the Help that it states "By default, a window already has the #PB_Shortcut_Tab and #PB_Shortcut_Tab|#PB_Shortcut_Shift shortcuts to handle tab and shift-tab correctly trough the gadgets." The simplest work-around seems to be what RASHAD suggested, using a loop that removes all keyboard shortcuts in the range 0 - 64000 except for #PB_Shortcut_Tab.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by netmaestro »

Removing shortcuts with #PB_All shouldn't change that - it should put the accelerator table back the way it was before the coder used any AddKeyboardShortcut.
BERESHEIT
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by ozzie »

I agree - or alternatively there should be another option to remove only the shortcuts added using the AddKeyboardShortcut() function. Maybe I'll add a Feature Request for this if the PB team decide the present behavior is not a bug.
PB Fanatic
User
User
Posts: 49
Joined: Wed Dec 17, 2014 11:54 am

Re: RemoveKeyboardShortcut with #PB_Shortcut_All kills tab

Post by PB Fanatic »

netmaestro wrote:Removing shortcuts with #PB_All shouldn't change that - it should put the accelerator table back the way it was before the coder used any AddKeyboardShortcut.
We need a new flag then, so instead of #PB_Shortcut_All, we can use #PB_Shortcut_Revert. All means all, IMO, and there may be reasons for a user to purposely remove Tab shortcuts as part of their decision to remove all.
Post Reply