From 783514fcff414ff15730e862e4c7df1e3640598c Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sun, 19 Aug 2012 21:01:36 +0200 Subject: [PATCH] Strip the numeric keypad flag for key events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This means pressing e.g. ⌘/ (using the slash on the numeric keypad) will still work to toggle comments. It also means that we can no longer bind specifically to the numeric keypad keys, but I don’t think anyone actually does that (given that few have numeric keypads). The ideal solution would be to first do a literal check and then, if there was no match and the key event had the numeric keypad flag set, do a test with this flag removed, but that would change the simple string compare we presently use plus the easy caching and binary search of finding the item that matches a key event, i.e. it would add complexity to the code with no known argument in favor of this flexibility. --- Frameworks/ns/src/ns.h | 2 +- Frameworks/ns/src/ns.mm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Frameworks/ns/src/ns.h b/Frameworks/ns/src/ns.h index 3f6c280e..57ea584a 100644 --- a/Frameworks/ns/src/ns.h +++ b/Frameworks/ns/src/ns.h @@ -7,7 +7,7 @@ PUBLIC std::string to_s (NSString* aString); PUBLIC std::string to_s (NSData* aString); -PUBLIC std::string to_s (NSEvent* anEvent); +PUBLIC std::string to_s (NSEvent* anEvent, bool preserveNumPadFlag = false); namespace ns { diff --git a/Frameworks/ns/src/ns.mm b/Frameworks/ns/src/ns.mm index 0da3a937..677a46d9 100644 --- a/Frameworks/ns/src/ns.mm +++ b/Frameworks/ns/src/ns.mm @@ -66,7 +66,7 @@ static bool is_ascii (std::string const& str) end if */ -std::string to_s (NSEvent* anEvent) +std::string to_s (NSEvent* anEvent, bool preserveNumPadFlag) { CGEventRef cgEvent = [anEvent CGEvent]; CGKeyCode key = (CGKeyCode)[anEvent keyCode]; @@ -81,7 +81,7 @@ std::string to_s (NSEvent* anEvent) if(flags & kCGEventFlagMaskNumericPad) { static std::string const numPadKeys = "0123456789=/*-+.,"; - if(numPadKeys.find(keyStringNoFlags) != std::string::npos) + if(preserveNumPadFlag && numPadKeys.find(keyStringNoFlags) != std::string::npos) newFlags |= kCGEventFlagMaskNumericPad; flags &= ~kCGEventFlagMaskControl; }