Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c2e2be

Browse filesBrowse files
committed
Merge pull request #1841 from cimarronm/macosx+modifiers
Fixes issue #1259 - Added modifier key handling for macosx backend
2 parents baaf1f4 + 7574ed4 commit 1c2e2be
Copy full SHA for 1c2e2be

File tree

Expand file treeCollapse file tree

1 file changed

+63
-53
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+63
-53
lines changed

‎src/_macosx.m

Copy file name to clipboardExpand all lines: src/_macosx.m
+63-53Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ - (const char*)convertKeyEvent:(NSEvent*)event;
413413
- (void)keyDown:(NSEvent*)event;
414414
- (void)keyUp:(NSEvent*)event;
415415
- (void)scrollWheel:(NSEvent *)event;
416-
- (void)flagsChanged:(NSEvent*)event;
416+
//- (void)flagsChanged:(NSEvent*)event;
417417
@end
418418

419419
@interface ScrollableButton : NSButton
@@ -5470,66 +5470,73 @@ - (void)removeRubberband
54705470
rubberband = NSZeroRect;
54715471
}
54725472

5473+
5474+
54735475
- (const char*)convertKeyEvent:(NSEvent*)event
54745476
{
5475-
NSString* text = [event charactersIgnoringModifiers];
5476-
unichar uc = [text characterAtIndex:0];
5477-
int i = (int)uc;
5478-
if ([event modifierFlags] & NSNumericPadKeyMask)
5479-
{
5480-
if (i > 256)
5481-
{
5482-
if (uc==NSLeftArrowFunctionKey) return "left";
5483-
else if (uc==NSUpArrowFunctionKey) return "up";
5484-
else if (uc==NSRightArrowFunctionKey) return "right";
5485-
else if (uc==NSDownArrowFunctionKey) return "down";
5486-
else if (uc==NSF1FunctionKey) return "f1";
5487-
else if (uc==NSF2FunctionKey) return "f2";
5488-
else if (uc==NSF3FunctionKey) return "f3";
5489-
else if (uc==NSF4FunctionKey) return "f4";
5490-
else if (uc==NSF5FunctionKey) return "f5";
5491-
else if (uc==NSF6FunctionKey) return "f6";
5492-
else if (uc==NSF7FunctionKey) return "f7";
5493-
else if (uc==NSF8FunctionKey) return "f8";
5494-
else if (uc==NSF9FunctionKey) return "f9";
5495-
else if (uc==NSF10FunctionKey) return "f10";
5496-
else if (uc==NSF11FunctionKey) return "f11";
5497-
else if (uc==NSF12FunctionKey) return "f12";
5498-
else if (uc==NSScrollLockFunctionKey) return "scroll_lock";
5499-
else if (uc==NSBreakFunctionKey) return "break";
5500-
else if (uc==NSInsertFunctionKey) return "insert";
5501-
else if (uc==NSDeleteFunctionKey) return "delete";
5502-
else if (uc==NSHomeFunctionKey) return "home";
5503-
else if (uc==NSEndFunctionKey) return "end";
5504-
else if (uc==NSPageUpFunctionKey) return "pageup";
5505-
else if (uc==NSPageDownFunctionKey) return "pagedown";
5506-
}
5507-
else if ((char)uc == '.') return "dec";
5508-
}
5509-
5510-
switch (i)
5511-
{
5512-
case 127: return "backspace";
5513-
case 13: return "enter";
5514-
case 3: return "enter";
5515-
case 27: return "escape";
5516-
default:
5517-
{
5518-
static char s[2];
5519-
s[0] = (char)uc;
5520-
s[1] = '\0';
5521-
return (const char*)s;
5522-
}
5523-
}
5477+
NSDictionary* specialkeymappings = [NSDictionary dictionaryWithObjectsAndKeys:
5478+
@"left", [NSNumber numberWithUnsignedLong:NSLeftArrowFunctionKey],
5479+
@"right", [NSNumber numberWithUnsignedLong:NSRightArrowFunctionKey],
5480+
@"up", [NSNumber numberWithUnsignedLong:NSUpArrowFunctionKey],
5481+
@"down", [NSNumber numberWithUnsignedLong:NSDownArrowFunctionKey],
5482+
@"f1", [NSNumber numberWithUnsignedLong:NSF1FunctionKey],
5483+
@"f2", [NSNumber numberWithUnsignedLong:NSF2FunctionKey],
5484+
@"f3", [NSNumber numberWithUnsignedLong:NSF3FunctionKey],
5485+
@"f4", [NSNumber numberWithUnsignedLong:NSF4FunctionKey],
5486+
@"f5", [NSNumber numberWithUnsignedLong:NSF5FunctionKey],
5487+
@"f6", [NSNumber numberWithUnsignedLong:NSF6FunctionKey],
5488+
@"f7", [NSNumber numberWithUnsignedLong:NSF7FunctionKey],
5489+
@"f8", [NSNumber numberWithUnsignedLong:NSF8FunctionKey],
5490+
@"f9", [NSNumber numberWithUnsignedLong:NSF9FunctionKey],
5491+
@"f10", [NSNumber numberWithUnsignedLong:NSF10FunctionKey],
5492+
@"f11", [NSNumber numberWithUnsignedLong:NSF11FunctionKey],
5493+
@"f12", [NSNumber numberWithUnsignedLong:NSF12FunctionKey],
5494+
@"f13", [NSNumber numberWithUnsignedLong:NSF13FunctionKey],
5495+
@"f14", [NSNumber numberWithUnsignedLong:NSF14FunctionKey],
5496+
@"f15", [NSNumber numberWithUnsignedLong:NSF15FunctionKey],
5497+
@"f16", [NSNumber numberWithUnsignedLong:NSF16FunctionKey],
5498+
@"f17", [NSNumber numberWithUnsignedLong:NSF17FunctionKey],
5499+
@"f18", [NSNumber numberWithUnsignedLong:NSF18FunctionKey],
5500+
@"f19", [NSNumber numberWithUnsignedLong:NSF19FunctionKey],
5501+
@"scroll_lock", [NSNumber numberWithUnsignedLong:NSScrollLockFunctionKey],
5502+
@"break", [NSNumber numberWithUnsignedLong:NSBreakFunctionKey],
5503+
@"insert", [NSNumber numberWithUnsignedLong:NSInsertFunctionKey],
5504+
@"delete", [NSNumber numberWithUnsignedLong:NSDeleteFunctionKey],
5505+
@"home", [NSNumber numberWithUnsignedLong:NSHomeFunctionKey],
5506+
@"end", [NSNumber numberWithUnsignedLong:NSEndFunctionKey],
5507+
@"pagedown", [NSNumber numberWithUnsignedLong:NSPageDownFunctionKey],
5508+
@"pageup", [NSNumber numberWithUnsignedLong:NSPageUpFunctionKey],
5509+
@"backspace", [NSNumber numberWithUnsignedLong:NSDeleteCharacter],
5510+
@"enter", [NSNumber numberWithUnsignedLong:NSEnterCharacter],
5511+
@"tab", [NSNumber numberWithUnsignedLong:NSTabCharacter],
5512+
@"enter", [NSNumber numberWithUnsignedLong:NSCarriageReturnCharacter],
5513+
@"backtab", [NSNumber numberWithUnsignedLong:NSBackTabCharacter],
5514+
@"escape", [NSNumber numberWithUnsignedLong:27],
5515+
nil
5516+
];
5517+
5518+
NSMutableString* returnkey = [NSMutableString string];
5519+
if ([event modifierFlags] & NSControlKeyMask)
5520+
[returnkey appendString:@"ctrl+" ];
5521+
if ([event modifierFlags] & NSAlternateKeyMask)
5522+
[returnkey appendString:@"alt+" ];
5523+
if ([event modifierFlags] & NSCommandKeyMask)
5524+
[returnkey appendString:@"cmd+" ];
5525+
5526+
unichar uc = [[event charactersIgnoringModifiers] characterAtIndex:0];
5527+
NSString* specialchar = [specialkeymappings objectForKey:[NSNumber numberWithUnsignedLong:uc]];
5528+
if (specialchar)
5529+
[returnkey appendString:specialchar];
5530+
else
5531+
[returnkey appendString:[event charactersIgnoringModifiers]];
55245532

5525-
return NULL;
5533+
return [returnkey UTF8String];
55265534
}
55275535

55285536
- (void)keyDown:(NSEvent*)event
55295537
{
55305538
PyObject* result;
55315539
const char* s = [self convertKeyEvent: event];
5532-
/* TODO: Handle ctrl, alt, super modifiers. qt4 has implemented these. */
55335540
PyGILState_STATE gstate = PyGILState_Ensure();
55345541
if (s==NULL)
55355542
{
@@ -5551,7 +5558,6 @@ - (void)keyUp:(NSEvent*)event
55515558
{
55525559
PyObject* result;
55535560
const char* s = [self convertKeyEvent: event];
5554-
/* TODO: Handle ctrl, alt, super modifiers. qt4 has implemented these. */
55555561
PyGILState_STATE gstate = PyGILState_Ensure();
55565562
if (s==NULL)
55575563
{
@@ -5592,6 +5598,9 @@ - (void)scrollWheel:(NSEvent*)event
55925598
PyGILState_Release(gstate);
55935599
}
55945600

5601+
/* This is all wrong. Address of pointer is being passed instead of pointer, keynames don't
5602+
match up with what the front-end and does the front-end even handle modifier keys by themselves?
5603+
55955604
- (void)flagsChanged:(NSEvent*)event
55965605
{
55975606
const char *s = NULL;
@@ -5611,6 +5620,7 @@ - (void)flagsChanged:(NSEvent*)event
56115620
56125621
PyGILState_Release(gstate);
56135622
}
5623+
*/
56145624
@end
56155625

56165626
@implementation ScrollableButton

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.