Skip to content

Commit

Permalink
Add support for macOS modifier keys (#45)
Browse files Browse the repository at this point in the history
* Add support for macOS modifier keys.

---------

Co-authored-by: Šimon Javora <simon.javora@kiwi.com>
Co-authored-by: Try <try9998@gmail.com>
  • Loading branch information
3 people authored Feb 6, 2023
1 parent e9ea0e7 commit 91145fc
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion Engine/system/api/macosapi.mm
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,72 @@ MouseEvent e(p.x,p.y,
SystemApi::dispatchKeyUp(cb,k,key);
return;
}
case NSEventTypeFlagsChanged:
case NSEventTypeFlagsChanged: {
NSEventModifierFlags flag = 0;
KeyEvent::KeyType kt = KeyEvent::K_NoKey;
Event::Modifier modifier = Event::M_NoModifier;

switch(evt.keyCode) {
case kVK_Command: {
flag = NSEventModifierFlagCommand;
kt = KeyEvent::K_LCommand;
modifier = Event::M_Command;
break;
}
case kVK_Shift: {
flag = NSEventModifierFlagShift;
kt = KeyEvent::K_LShift;
modifier = Event::M_Shift;
break;
}
case kVK_Option: {
flag = NSEventModifierFlagOption;
kt = KeyEvent::K_LAlt;
modifier = Event::M_Alt;
break;
}
case kVK_Control: {
flag = NSEventModifierFlagControl;
kt = KeyEvent::K_LControl;
modifier = Event::M_Ctrl;
break;
}
case kVK_RightCommand: {
flag = NSEventModifierFlagCommand;
kt = KeyEvent::K_RCommand;
modifier = Event::M_Command;
break;
}
case kVK_RightShift: {
flag = NSEventModifierFlagShift;
kt = KeyEvent::K_RShift;
modifier = Event::M_Shift;
break;
}
case kVK_RightOption: {
flag = NSEventModifierFlagOption;
kt = KeyEvent::K_RAlt;
modifier = Event::M_Alt;
break;
}
case kVK_RightControl: {
flag = NSEventModifierFlagControl;
kt = KeyEvent::K_RControl;
modifier = Event::M_Ctrl;
break;
}
default: break;
}

auto isDown = evt.modifierFlags & flag;
auto eType = (isDown ? Event::KeyDown : Event::KeyUp);
auto k = KeyEvent(kt,modifier,eType);

if(isDown)
SystemApi::dispatchKeyDown(cb,k,evt.keyCode); else
SystemApi::dispatchKeyUp(cb,k,evt.keyCode);
return;
}
case NSEventTypeAppKitDefined:
break;
case NSEventTypeMouseEntered:
Expand Down

0 comments on commit 91145fc

Please sign in to comment.