mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Added a conservative set of key modifiers.
This commit is contained in:
+51
-9
@@ -201,6 +201,22 @@ static void centerCursor(_GLFWwindow *window)
|
||||
|
||||
@end
|
||||
|
||||
// Converts Mac OS X key modifiers into GLFW ones
|
||||
//
|
||||
static int convertKeyMods(NSUInteger flags)
|
||||
{
|
||||
int mods = 0;
|
||||
|
||||
if (flags & NSShiftKeyMask)
|
||||
mods |= GLFW_MOD_SHIFT;
|
||||
if (flags & NSControlKeyMask)
|
||||
mods |= GLFW_MOD_CTRL;
|
||||
if (flags & NSAlternateKeyMask)
|
||||
mods |= GLFW_MOD_ALT;
|
||||
|
||||
return mods;
|
||||
}
|
||||
|
||||
// Converts a Mac OS X keycode to a GLFW keycode
|
||||
//
|
||||
static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
@@ -413,7 +429,10 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)mouseDown:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
|
||||
_glfwInputMouseClick(window,
|
||||
GLFW_MOUSE_BUTTON_LEFT,
|
||||
GLFW_PRESS,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)mouseDragged:(NSEvent *)event
|
||||
@@ -423,7 +442,10 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)mouseUp:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE);
|
||||
_glfwInputMouseClick(window,
|
||||
GLFW_MOUSE_BUTTON_LEFT,
|
||||
GLFW_RELEASE,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)mouseMoved:(NSEvent *)event
|
||||
@@ -442,7 +464,10 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)rightMouseDown:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS);
|
||||
_glfwInputMouseClick(window,
|
||||
GLFW_MOUSE_BUTTON_RIGHT,
|
||||
GLFW_PRESS,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)rightMouseDragged:(NSEvent *)event
|
||||
@@ -452,12 +477,18 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)rightMouseUp:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE);
|
||||
_glfwInputMouseClick(window,
|
||||
GLFW_MOUSE_BUTTON_RIGHT,
|
||||
GLFW_RELEASE,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)otherMouseDown:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window, [event buttonNumber], GLFW_PRESS);
|
||||
_glfwInputMouseClick(window,
|
||||
[event buttonNumber],
|
||||
GLFW_PRESS,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)otherMouseDragged:(NSEvent *)event
|
||||
@@ -467,7 +498,10 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)otherMouseUp:(NSEvent *)event
|
||||
{
|
||||
_glfwInputMouseClick(window, [event buttonNumber], GLFW_RELEASE);
|
||||
_glfwInputMouseClick(window,
|
||||
[event buttonNumber],
|
||||
GLFW_RELEASE,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)mouseExited:(NSEvent *)event
|
||||
@@ -503,7 +537,12 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
- (void)keyDown:(NSEvent *)event
|
||||
{
|
||||
_glfwInputKey(window, convertMacKeyCode([event keyCode]), GLFW_PRESS);
|
||||
const NSUInteger mods = [event modifierFlags];
|
||||
|
||||
_glfwInputKey(window,
|
||||
convertMacKeyCode([event keyCode]),
|
||||
GLFW_PRESS,
|
||||
convertKeyMods(mods));
|
||||
|
||||
if ([event modifierFlags] & NSCommandKeyMask)
|
||||
return;
|
||||
@@ -530,12 +569,15 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
key = convertMacKeyCode([event keyCode]);
|
||||
if (key != -1)
|
||||
_glfwInputKey(window, key, action);
|
||||
_glfwInputKey(window, key, action, convertKeyMods([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)keyUp:(NSEvent *)event
|
||||
{
|
||||
_glfwInputKey(window, convertMacKeyCode([event keyCode]), GLFW_RELEASE);
|
||||
_glfwInputKey(window,
|
||||
convertMacKeyCode([event keyCode]),
|
||||
GLFW_RELEASE,
|
||||
convertKeyMods([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)scrollWheel:(NSEvent *)event
|
||||
|
||||
Reference in New Issue
Block a user