Page 1 of 1

[solved] Button focus or lack of it

Posted: Wed Mar 23, 2016 11:53 pm
by Julian
I'm sure there's a simple solution. How do I enable the blue highlighting of buttons (focus) when pressing tab, as happens with other mac apps including the PB editor?

It just works in windows, so I'm a bit confused.

Thanks

Code: Select all

OpenWindow(0, 0, 0, 100, 100, "Test")
ButtonGadget(0, 0, 0, 100, 30, "Test1")
ButtonGadget(1, 0, 35, 100, 30, "Test2")

Repeat
  
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Button focus or lack of it

Posted: Thu Mar 24, 2016 5:56 am
by wilbert

Re: Button focus or lack of it

Posted: Thu Mar 24, 2016 1:28 pm
by Julian
Thanks Wilbert, but there's nothing in that post that turns this feature on. It would seem the the feature shows when a StringGadget (or list) is selected, the tab shows then and cycles through the controls, but it doesnt work when the window is opened and nothing is clicked.

Any ideas?

Re: Button focus or lack of it

Posted: Thu Mar 24, 2016 1:40 pm
by wilbert
Sorry, I misread your question; thought you were asking how to set the default button (which makes it blue).
From what I read online, a NSButton normally can't have keyboard focus. Maybe some sort of accessibility option can enable it :?

Re: Button focus or lack of it

Posted: Thu Mar 24, 2016 1:56 pm
by Julian
Hmm odd, purebasic does it on the debug window when you run a program and click the title of the debug window, the "Copy all" button is already selected with a blue border.

Thanks thought, I'll keep looking.

Re: Button focus or lack of it

Posted: Thu Mar 24, 2016 3:58 pm
by Shardik
The solution is very easy and doesn't require any API. You only need to use

Code: Select all

SetActiveGadget(#ButtonGadget)
and voilĂ : your button displays the wanted blue border and you may change the focus by using the <Tab> key... :wink:

Code: Select all

OpenWindow(0, 270, 100, 200, 145, "Highlighted button")
ButtonGadget(0, 40, 20, 120, 25, "Test 1")
ButtonGadget(1, 40, 60, 120, 25, "Test 2")
ButtonGadget(2, 40, 100, 120, 25, "Test 3")
SetActiveGadget(0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Button focus or lack of it

Posted: Thu Mar 24, 2016 4:10 pm
by Julian
Ha! So simple I overlooked it, thanks Shardik

Re: [solved] Button focus or lack of it

Posted: Mon Jul 08, 2019 6:51 pm
by doctorized
Some windows apps, not writen in PB, gives you the opportunity to write something in a textbox, the active button remains active while typing and by pressing keyboard Enter the button is pressed and does the job it should do. Is there a way to achieve it?

Re: [solved] Button focus or lack of it

Posted: Mon Jul 08, 2019 8:21 pm
by mk-soft
Update...

Is better to add and remove shortcut key

Code: Select all

;-TOP

Enumeration formMenu
  #Menu_Return
EndEnumeration

OpenWindow(0, 270, 100, 200, 145, "Highlighted button")
ButtonGadget(0, 40, 20, 120, 25, "Ok", #PB_Button_Default)
ButtonGadget(1, 40, 60, 120, 25, "Cancel")
StringGadget(2, 40, 100, 120, 25, "Text")
SetActiveGadget(0)


; AddKeyboardShortcut(0, #PB_Shortcut_Return, #Menu_Return)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Menu
      Select EventMenu()
        Case #Menu_Return
          ;Debug GetGadgetText(2)
          PostEvent(#PB_Event_Gadget, 0, 0, #PB_EventType_LeftClick)
          
      EndSelect
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Debug "Button Ok - " + GetGadgetText(2)
        Case 1
          Debug "Button Cancel"
        Case 2
          If EventType() = #PB_EventType_Focus
            AddKeyboardShortcut(0, #PB_Shortcut_Return, #Menu_Return)
          ElseIf EventType() = #PB_EventType_LostFocus
            RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
          EndIf
            
      EndSelect
  
  EndSelect
ForEver