jdl
jdl

Reputation: 6333

How to get "focus" to a specific NSView programmatically?

I switch from displaying one NSView to another. But to be able to receive keystrokes typed in from the user, the user must first click the mouse on the NSView. I want the user to be able to type-in without having to click on the NSView...

Upvotes: 4

Views: 2232

Answers (1)

Nef10
Nef10

Reputation: 946

There is a good guide from Apple on Event Handling Basics. See the "Preparing a Custom View for Receiving Events" and "Setting the First Responder" sections.

TL;DR: You have to override acceptsFirstResponder on your custom NSView to return true and then call makeFirstResponder on the NSWindow with your view as argument.

Upvotes: 4

Related Questions