[solved] Button focus or lack of it

Mac OSX specific forum
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

[solved] Button focus or lack of it

Post 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
Last edited by Julian on Thu Mar 24, 2016 4:10 pm, edited 1 time in total.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Button focus or lack of it

Post by wilbert »

Windows (x64)
Raspberry Pi OS (Arm64)
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Button focus or lack of it

Post 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?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Button focus or lack of it

Post 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 :?
Windows (x64)
Raspberry Pi OS (Arm64)
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Button focus or lack of it

Post 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.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Button focus or lack of it

Post 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
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Button focus or lack of it

Post by Julian »

Ha! So simple I overlooked it, thanks Shardik
User avatar
doctorized
Addict
Addict
Posts: 854
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: [solved] Button focus or lack of it

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [solved] Button focus or lack of it

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply