Jesus
Jesus

Reputation: 8586

how to close a NSWindowController without close button by using a custom shortcut without Xcode

I have a NSWindowController which closes itself by pressing the 'x' key and works great

enter image description here

as you see, very clear my Window, this is the code

-(void)keyDown:(NSEvent *)theEvent{

    //If the key is X just closes the window
    if ([theEvent.characters.uppercaseString isEqualToString:@"X"]) {
        [self.window performClose:self];
    }
}

but when I remove the TitleBar or the close control it just stops working...

enter image description here

I want it this way because its required to have my windows without buttons, just to close or do task by shortcuts and commands, in this case the X button to close, how to perform this in a NSWindowController without the close control or titlebar

thanks for the support

Upvotes: 0

Views: 356

Answers (1)

Jesús Ayala
Jesús Ayala

Reputation: 2791

with this:

-(void)keyDown:(NSEvent *)theEvent{

    //If the key is X just closes the window
    if ([theEvent.characters.uppercaseString isEqualToString:@"X"]) {
        [self close];
    }
}

Upvotes: 1

Related Questions