3
votes

I'm developing an on screen keyboard application for OS X, similar to the one that's built in to the operating system (Keyboard Viewer). I seem to have hit a wall as I'm not sure how I can accept click events from buttons and not steal focus from the currently activated application. I know this is possible since there are apps that already do this, e.g. AssistiveWere's KeyStrokes.

So my question is this: How can I make my window receive mouse events and handle them without getting activated?

P.S. I'm not very experienced in OS X development and this is my first Swift project, so excuses if this is a trivial problem.

1
You need to be able to have permission of the user to have Accessibility access. After that you need to register a NotificationListener to receive keyboard and mouse events on the OS/System scale.user1467267

1 Answers

4
votes

You need to make your window an instance of NSPanel (or a subclass), include NSNonactivatingPanelMask in its styleMask, and set becomesKeyOnlyIfNeeded to true. (The style mask can be controlled in IB.) You probably also want it to be floating so it's always above normal windows, so set floatingPanel to true, too.