Hot to move focus to a button?

  • Hello,

    I'm trying to move keyboard cursor to a button but NSButton hasn't a setFocus method.

    How can I move the keyboard focus to a control?

    thanks

    Regards
    Jonathan Chacón Barbero
      Accessibility, usability and new technologies consultant

    Phone: +34 679953948
    e-Mail: <jonathan.chacon...>
    Blog: http://programaraciegas.weblog.discapnet.es
    Twitter: http://www.twitter.com/jonathanchacon
    LinkedIn: http://es.linkedin.com/in/jonathanchacon
    Facebook: http://www.facebook.com/jonathan.chacon.barbero
    Messenger: <Tyflos...>
    Skype: Tyflos_
    Ping for iPhone: jchacon
  • Hi Jonathan

    > I'm trying to move keyboard cursor to a button but NSButton hasn't a setFocus method.
    >
    > How can I move the keyboard focus to a control?

    [window makeFirstResponder:theButton];

    Joanna

    --
    Joanna Carter
    Carter Consulting
  • On Sat, Mar 6, 2010 at 12:20 PM, Jonathan Chacón <tyflos2001...> wrote:
    > How can I move the keyboard focus to a control?

    Buttons don't accept keyboard focus. See the documentation for
    -[NSView canBecomeKeyView] and the related conceptual documentation.

    --Kyle Sluder
  • Hi Kyle

    > Buttons don't accept keyboard focus. See the documentation for
    > -[NSView canBecomeKeyView] and the related conceptual documentation.

    I realise this to be what the docs say but, if you use -makeFirstResponder: the focus ring is applied to the chosen button and pressing the spacebar calls the connected action, which is, surely, the desired end result of "setting focus".

    Joanna

    --
    Joanna Carter
    Carter Consulting
  • On Mar 7, 2010, at 3:53 AM, Joanna Carter wrote:

    > Hi Kyle
    >
    >> Buttons don't accept keyboard focus. See the documentation for
    >> -[NSView canBecomeKeyView] and the related conceptual documentation.
    >
    > I realise this to be what the docs say but, if you use -makeFirstResponder: the focus ring is applied to the chosen button and pressing the spacebar calls the connected action, which is, surely, the desired end result of "setting focus".

    All you need to do is properly set up the key view loop in IB.  i.e. connect the 'nextKeyView' outlets.

    If your UI is something like this:

    Prompt: [edit field]

    (button1) (button2)

    set 'nextKeyView' of 'edit field' to 'button1'.  Then, 'button1' to 'button2' and finally 'button2' back to the 'edit field'.

    Also, ensure to set the first responder as needed.

    When Full Keyboard Access is off, users will only be able to tab amongst controls that are text boxes or lists.  Otherwise, when on, they will be able to tab amongst all controls.

    You should get automatic behavior 99% of the time (i.e. you never have to call makeFirstResponder: manually).  There are cases where you need to do so when you have very complex UI involving tabless tabviews (usually nested).  In response to selected tab changes, you can "rewire" the keyloop manually as needed and re-establish the current control that should have focus.
    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • Hi Ricky

    > All you need to do is properly set up the key view loop in IB.  i.e. connect the 'nextKeyView' outlets.
    >
    > ...

    A very good point. I was assuming that Jonathan already knew this <slaps self on wrist :-)> and just wanted to set focus to a button, other than by moving through the "tab order".

    Joanna

    --
    Joanna Carter
    Carter Consulting
  • On Sat, 6 Mar 2010 16:25:57 -0800, Kyle Sluder <kyle.sluder...> said:
    > On Sat, Mar 6, 2010 at 12:20 PM, Jonathan Chacón <tyflos2001...>  wrote:
    >> How can I move the keyboard focus to a control?
    >
    > Buttons don't accept keyboard focus

    They do on my machine. It all depends on how the user has set up Full
    Keyboard Access in the Keyboard prefs. m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    http://www.tidbits.com/matt/default.html#applescriptthings
  • On Sun, Mar 7, 2010 at 11:44 AM, Matt Neuburg <matt...> wrote:
    > On Sat, 6 Mar 2010 16:25:57 -0800, Kyle Sluder <kyle.sluder...> said:
    >> Buttons don't accept keyboard focus
    >
    > They do on my machine. It all depends on how the user has set up Full
    > Keyboard Access in the Keyboard prefs. m.

    Okay, but that is not the default configuration. The OP cannot rely on
    this behavior.

    --Kyle Sluder
previous month march 2010 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today