Contribute  :  Calendar  :  Advanced Search  :  Site Statistics  :  Directory  :  Files to download  :  Links for developers  :  Privacy policy  :  Web Resources  :  Polls  
    MacOSX Guru Site Information, tips and tricks, FAQ for Mac OS X developers    
 Welcome to MacOSX Guru Site
 Friday, April 19 2019 @ 08:11 AM BST

NSBorderlessWindowMask and key events

Cocoa Development FAQWhen a window is created with NSBorderlessWindowMask, it doesn't receive key events anymore.
How to solve that ?

You have to create you own subclass of
and implements the following methods:

- (BOOL) canBecomeKeyWindow
    return YES;

- (void)keyDown:(NSEvent *)theEvent
    // your code here

- (void)keyUp:(NSEvent *)theEvent
    // your code here
and of course don't forget to change your initialization code to use the new window class or to change the class of the window in your nibs.

What's Related

Story Options

NSBorderlessWindowMask and key events | 1 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
NSBorderlessWindowMask and key events
Authored by: peternlewis on Tuesday, July 22 2008 @ 06:06 AM BST

Another thing that caught me out with NSBorderlessWindowMask is that if you are a LSUIElement background only application, and you have a Carbon run loop, then if you override initWithContentRect to specify a styleMask of NSBorderlessWindowMask, it kills the other styleMask flags as well, importantly including the Non Activating flag, which means the window does not start as the key window even if you makeKeyAndOrderFront.

So instead of using styleMask: NSBorderlessWindowMask, use styleMask:styleMask&~NSTitledWindowMask (after making sure your nib has Non Activating turned on, and Close, Minimize and Zoom turned off).

Also, remember to use [NSApp activateIgnoringOtherApps:YES]; otherwise again, the window will not become the key window.

Two days of pain were required to figure out this Carbon/Cocoa interaction issue. I really hope this helps someone else!

Keyboard Maestro Macros for your Mac

 Copyright © 2019 MacOSX Guru Site
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.47 seconds