From b44d11312c8dd908a8e6d3c83e8f9773a893e15c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 5 Sep 2018 23:10:18 +0200 Subject: Make "Quit" button work on "q" or "Escape" key press Previously I only had a key equivalent on the "Escape" key because you can only set a single key equivalent. But I wanted the "Quit" button to work on both "Escape" and "q" presses. I tried to do this by overriding `performKeyEquivalent:`: - (BOOL)performKeyEquivalent:(NSEvent *)theEvent { if ([[theEvent characters] isEqualToString:@"q"] || [theEvent keyCode] == kVK_Escape) { NSLog(@"%@", theEvent); return YES; } return [super performKeyEquivalent:theEvent]; } The method was called and it logged correctly, but the `IBAction` wouldn't run. Maybe this doesn't work for what I want it to? Can't figure out what the problem is. Didn't want to deal any more so just overrode `keyDown:` instead and got rid of the `IBAction`, just terminating the application in code. --- CopyMailto/QuitButton.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CopyMailto/QuitButton.h (limited to 'CopyMailto/QuitButton.h') diff --git a/CopyMailto/QuitButton.h b/CopyMailto/QuitButton.h new file mode 100644 index 0000000..73c2e9d --- /dev/null +++ b/CopyMailto/QuitButton.h @@ -0,0 +1,16 @@ +// +// QuitButton.h +// CopyMailto +// +// Created by tw on 9/5/18. +// Copyright © 2018 tw. All rights reserved. +// + +#import +#import + +@interface QuitButton : NSButton + +- (void)keyDown:(NSEvent *)theEvent; + +@end -- cgit v1.2.3