Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc77052

Browse files
committed
MNT: Add modifier key press handling to macosx backend
The flagsChanged event handles single presses of modifier keys, so we need to send the corresponding string to our key press handlers from within that routine. Modifier + second key is handled within the KeyUp/KeyDown routines already, so leave those alone.
1 parent b09aad2 commit fc77052

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/_macosx.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ - (void)keyDown:(NSEvent*)event;
264264
- (void)keyUp:(NSEvent*)event;
265265
- (void)scrollWheel:(NSEvent *)event;
266266
- (BOOL)acceptsFirstResponder;
267-
//- (void)flagsChanged:(NSEvent*)event;
267+
- (void)flagsChanged:(NSEvent*)event;
268268
@end
269269

270270
/* ---------------------------- Python classes ---------------------------- */
@@ -2066,29 +2066,31 @@ - (BOOL)acceptsFirstResponder
20662066
return YES;
20672067
}
20682068

2069-
/* This is all wrong. Address of pointer is being passed instead of pointer, keynames don't
2070-
match up with what the front-end and does the front-end even handle modifier keys by themselves?
2071-
2069+
// flagsChanged gets called on single modifier keypresses
2070+
// The modifier + second key gets handled in convertKeyEvent in KeyUp/KeyDown
20722071
- (void)flagsChanged:(NSEvent*)event
20732072
{
2074-
const char *s = NULL;
2075-
if (([event modifierFlags] & NSControlKeyMask) == NSControlKeyMask)
2073+
const char* s = NULL;
2074+
if ([event modifierFlags] & NSEventModifierFlagControl)
20762075
s = "control";
2077-
else if (([event modifierFlags] & NSShiftKeyMask) == NSShiftKeyMask)
2076+
else if ([event modifierFlags] & NSEventModifierFlagShift)
20782077
s = "shift";
2079-
else if (([event modifierFlags] & NSAlternateKeyMask) == NSAlternateKeyMask)
2078+
else if ([event modifierFlags] & NSEventModifierFlagOption)
20802079
s = "alt";
2080+
else if ([event modifierFlags] & NSEventModifierFlagCommand)
2081+
s = "cmd";
2082+
else if ([event modifierFlags] & NSEventModifierFlagCapsLock)
2083+
s = "caps_lock";
20812084
else return;
20822085
PyGILState_STATE gstate = PyGILState_Ensure();
2083-
PyObject* result = PyObject_CallMethod(canvas, "key_press_event", "s", &s);
2086+
PyObject* result = PyObject_CallMethod(canvas, "key_press_event", "s", s);
20842087
if(result)
20852088
Py_DECREF(result);
20862089
else
20872090
PyErr_Print();
20882091

20892092
PyGILState_Release(gstate);
20902093
}
2091-
*/
20922094
@end
20932095

20942096
static PyObject*

0 commit comments

Comments
 (0)