mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-19 15:27:55 +00:00
[Mac] Implemented modifier keys
This commit is contained in:
parent
4066ba8355
commit
56e4b3cc85
|
@ -34,6 +34,7 @@ using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace OpenTK.Platform.MacOS
|
namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
|
@ -362,7 +363,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenTK.Input.Key key;
|
Key key;
|
||||||
switch (evt.KeyboardEventKind)
|
switch (evt.KeyboardEventKind)
|
||||||
{
|
{
|
||||||
case KeyboardEventKind.RawKeyRepeat:
|
case KeyboardEventKind.RawKeyRepeat:
|
||||||
|
@ -371,29 +372,11 @@ namespace OpenTK.Platform.MacOS
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyboardEventKind.RawKeyDown:
|
case KeyboardEventKind.RawKeyDown:
|
||||||
Keymap.TryGetValue(code, out key);
|
ProcessKeyDown(code);
|
||||||
// Legacy keyboard API
|
|
||||||
InputDriver.Keyboard[0].SetKey(key, (uint)code, true);
|
|
||||||
|
|
||||||
// Raise KeyDown for new keyboard API
|
|
||||||
mKeyDownArgs.Key = key;
|
|
||||||
KeyDown(this, mKeyDownArgs);
|
|
||||||
|
|
||||||
// Raise KeyPress for new keyboard API
|
|
||||||
if (!Char.IsControl(mKeyPressArgs.KeyChar))
|
|
||||||
{
|
|
||||||
OnKeyPress(mKeyPressArgs);
|
|
||||||
}
|
|
||||||
return OSStatus.NoError;
|
return OSStatus.NoError;
|
||||||
|
|
||||||
case KeyboardEventKind.RawKeyUp:
|
case KeyboardEventKind.RawKeyUp:
|
||||||
Keymap.TryGetValue(code, out key);
|
ProcessKeyUp(code);
|
||||||
// Legacy keyboard API
|
|
||||||
InputDriver.Keyboard[0].SetKey(key, (uint)code, false);
|
|
||||||
|
|
||||||
// Raise KeyUp for new keyboard API
|
|
||||||
mKeyUpArgs.Key = key;
|
|
||||||
KeyUp(this, mKeyUpArgs);
|
|
||||||
return OSStatus.NoError;
|
return OSStatus.NoError;
|
||||||
|
|
||||||
case KeyboardEventKind.RawKeyModifiersChanged:
|
case KeyboardEventKind.RawKeyModifiersChanged:
|
||||||
|
@ -611,6 +594,56 @@ namespace OpenTK.Platform.MacOS
|
||||||
charCode = API.GetEventKeyboardChar(inEvent);
|
charCode = API.GetEventKeyboardChar(inEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessKeyDown(MacOSKeyCode code)
|
||||||
|
{
|
||||||
|
Key key;
|
||||||
|
Keymap.TryGetValue(code, out key);
|
||||||
|
|
||||||
|
// Legacy keyboard API
|
||||||
|
KeyboardDevice keyboard = InputDriver.Keyboard[0];
|
||||||
|
keyboard.SetKey(key, (uint)code, true);
|
||||||
|
|
||||||
|
// Raise KeyDown for new keyboard API
|
||||||
|
mKeyDownArgs.Key = key;
|
||||||
|
mKeyDownArgs.Modifiers = keyboard.GetModifiers();
|
||||||
|
|
||||||
|
KeyDown(this, mKeyDownArgs);
|
||||||
|
|
||||||
|
// Raise KeyPress for new keyboard API
|
||||||
|
if (!Char.IsControl(mKeyPressArgs.KeyChar))
|
||||||
|
{
|
||||||
|
OnKeyPress(mKeyPressArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessKeyUp(MacOSKeyCode code)
|
||||||
|
{
|
||||||
|
Key key;
|
||||||
|
Keymap.TryGetValue(code, out key);
|
||||||
|
|
||||||
|
// Legacy keyboard API
|
||||||
|
KeyboardDevice keyboard = InputDriver.Keyboard[0];
|
||||||
|
keyboard.SetKey(key, (uint)code, false);
|
||||||
|
|
||||||
|
// Raise KeyUp for new keyboard API
|
||||||
|
mKeyUpArgs.Key = key;
|
||||||
|
mKeyDownArgs.Modifiers = keyboard.GetModifiers();
|
||||||
|
|
||||||
|
KeyUp(this, mKeyUpArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessKey(MacOSKeyCode code, bool pressed)
|
||||||
|
{
|
||||||
|
if (pressed)
|
||||||
|
{
|
||||||
|
ProcessKeyDown(code);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProcessKeyUp(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ProcessModifierKey(IntPtr inEvent)
|
private void ProcessModifierKey(IntPtr inEvent)
|
||||||
{
|
{
|
||||||
MacOSKeyModifiers modifiers = API.GetEventKeyModifiers(inEvent);
|
MacOSKeyModifiers modifiers = API.GetEventKeyModifiers(inEvent);
|
||||||
|
@ -621,25 +654,32 @@ namespace OpenTK.Platform.MacOS
|
||||||
bool option = (modifiers & MacOSKeyModifiers.Option) != 0 ? true : false;
|
bool option = (modifiers & MacOSKeyModifiers.Option) != 0 ? true : false;
|
||||||
bool shift = (modifiers & MacOSKeyModifiers.Shift) != 0 ? true : false;
|
bool shift = (modifiers & MacOSKeyModifiers.Shift) != 0 ? true : false;
|
||||||
|
|
||||||
Debug.Print("Modifiers Changed: {0}", modifiers);
|
|
||||||
|
|
||||||
Input.KeyboardDevice keyboard = InputDriver.Keyboard[0];
|
Input.KeyboardDevice keyboard = InputDriver.Keyboard[0];
|
||||||
|
|
||||||
if (keyboard[OpenTK.Input.Key.AltLeft] ^ option)
|
if (keyboard[OpenTK.Input.Key.AltLeft] ^ option)
|
||||||
keyboard.SetKey(OpenTK.Input.Key.AltLeft, (uint)MacOSKeyCode.OptionAlt, option);
|
{
|
||||||
|
ProcessKey(MacOSKeyCode.OptionAlt, option);
|
||||||
|
}
|
||||||
|
|
||||||
if (keyboard[OpenTK.Input.Key.ShiftLeft] ^ shift)
|
if (keyboard[OpenTK.Input.Key.ShiftLeft] ^ shift)
|
||||||
keyboard.SetKey(OpenTK.Input.Key.ShiftLeft, (uint)MacOSKeyCode.Shift, shift);
|
{
|
||||||
|
ProcessKey(MacOSKeyCode.Shift, shift);
|
||||||
|
}
|
||||||
|
|
||||||
if (keyboard[OpenTK.Input.Key.WinLeft] ^ command)
|
if (keyboard[OpenTK.Input.Key.WinLeft] ^ command)
|
||||||
keyboard.SetKey(OpenTK.Input.Key.WinLeft, (uint)MacOSKeyCode.Command, command);
|
{
|
||||||
|
ProcessKey(MacOSKeyCode.Command, command);
|
||||||
|
}
|
||||||
|
|
||||||
if (keyboard[OpenTK.Input.Key.ControlLeft] ^ control)
|
if (keyboard[OpenTK.Input.Key.ControlLeft] ^ control)
|
||||||
keyboard.SetKey(OpenTK.Input.Key.ControlLeft, (uint)MacOSKeyCode.Control, control);
|
{
|
||||||
|
ProcessKey(MacOSKeyCode.Control, control);
|
||||||
|
}
|
||||||
|
|
||||||
if (keyboard[OpenTK.Input.Key.CapsLock] ^ caps)
|
if (keyboard[OpenTK.Input.Key.CapsLock] ^ caps)
|
||||||
keyboard.SetKey(OpenTK.Input.Key.CapsLock, (uint)MacOSKeyCode.CapsLock, caps);
|
{
|
||||||
|
ProcessKey(MacOSKeyCode.CapsLock, caps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect GetClientSize()
|
Rect GetClientSize()
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
// comments indicate members of the Key enum that are missing
|
// comments indicate members of the Key enum that are missing
|
||||||
|
|
||||||
Add(MacOSKeyCode.A, Key.A);
|
Add(MacOSKeyCode.A, Key.A);
|
||||||
// AltLeft
|
Add(MacOSKeyCode.OptionAlt, Key.AltLeft);
|
||||||
// AltRight
|
// AltRight
|
||||||
Add(MacOSKeyCode.B, Key.B);
|
Add(MacOSKeyCode.B, Key.B);
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
// Capslock
|
// Capslock
|
||||||
// Clear
|
// Clear
|
||||||
Add(MacOSKeyCode.Comma, Key.Comma);
|
Add(MacOSKeyCode.Comma, Key.Comma);
|
||||||
// ControlLeft
|
Add(MacOSKeyCode.Control, Key.ControlLeft);
|
||||||
// ControlRight
|
// ControlRight
|
||||||
Add(MacOSKeyCode.D, Key.D);
|
Add(MacOSKeyCode.D, Key.D);
|
||||||
Add(MacOSKeyCode.Del, Key.Delete);
|
Add(MacOSKeyCode.Del, Key.Delete);
|
||||||
|
@ -139,7 +139,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
Add(MacOSKeyCode.S, Key.S);
|
Add(MacOSKeyCode.S, Key.S);
|
||||||
// ScrollLock
|
// ScrollLock
|
||||||
Add(MacOSKeyCode.Semicolon, Key.Semicolon);
|
Add(MacOSKeyCode.Semicolon, Key.Semicolon);
|
||||||
//Key.ShiftLeft
|
Add(MacOSKeyCode.Shift, Key.ShiftLeft);
|
||||||
//Key.ShiftRight
|
//Key.ShiftRight
|
||||||
Add(MacOSKeyCode.Slash, Key.Slash);
|
Add(MacOSKeyCode.Slash, Key.Slash);
|
||||||
// Key.Sleep
|
// Key.Sleep
|
||||||
|
@ -151,7 +151,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
Add(MacOSKeyCode.Up, Key.Up);
|
Add(MacOSKeyCode.Up, Key.Up);
|
||||||
Add(MacOSKeyCode.V, Key.V);
|
Add(MacOSKeyCode.V, Key.V);
|
||||||
Add(MacOSKeyCode.W, Key.W);
|
Add(MacOSKeyCode.W, Key.W);
|
||||||
// WinKeyLeft
|
Add(MacOSKeyCode.Command, Key.WinLeft);
|
||||||
// WinKeyRight
|
// WinKeyRight
|
||||||
Add(MacOSKeyCode.X, Key.X);
|
Add(MacOSKeyCode.X, Key.X);
|
||||||
Add(MacOSKeyCode.Y, Key.Y);
|
Add(MacOSKeyCode.Y, Key.Y);
|
||||||
|
|
Loading…
Reference in a new issue