static void CharModsCallback(Glfw.Window window, uint codepoint, Glfw.KeyMods mods) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Character 0x{3} ({4}) with modifiers ({5}) input", m_Counter++, slot.Number, Glfw.GetTime(), codepoint, GetCharacterString(codepoint), GetModsName(mods)); }
private static void UnicodeCallback(Glfw.Window window, uint codepoint, Glfw.KeyMods mods) { var engineWindow = dictionary[window]; engineWindow.UnicodeInput?.Invoke(engineWindow, new UnicodeInputEventArgs() { CodePoint = codepoint, Modifiers = mods }); }
static string GetModsName(Glfw.KeyMods mods) { string name = ""; if ((mods & Glfw.KeyMods.Shift) > 0) name += " shift"; if ((mods & Glfw.KeyMods.Control) > 0) name += " control"; if ((mods & Glfw.KeyMods.Alt) > 0) name += " alt"; if ((mods & Glfw.KeyMods.Super) > 0) name += " super"; return name; }
static string GetModsName(Glfw.KeyMods mods) { var name = ""; if ((mods & Glfw.KeyMods.Shift) > 0) { name += " shift"; } if ((mods & Glfw.KeyMods.Control) > 0) { name += " control"; } if ((mods & Glfw.KeyMods.Alt) > 0) { name += " alt"; } if ((mods & Glfw.KeyMods.Super) > 0) { name += " super"; } return(name); }
private void handleMouseButton(Glfw.Window window, Glfw.MouseButton button, bool state, Glfw.KeyMods mods) { cursorPressed = state; InputEvent(new InputEvent { TouchEvent = new TouchEvent { Point = new Point(cursorX, cursorY), Action = cursorPressed ? TouchAction.Pressed : TouchAction.Released } }); }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { var slot = m_Slots[window]; string name = Glfw.GetKeyName(key, scancode); if (!string.IsNullOrEmpty(name)) { Log("{0} to {1} at {2}: Key 0x{3} Scancode 0x{4} ({5}) ({6}) ({7}) was {8}", m_Counter++, slot.Number, Glfw.GetTime(), (int)key, scancode, GetKeyName(key), name, GetModsName(mods), GetActioName(state)); } else { Log("{0} to {1} at {2}: Key 0x{3} Scancode 0x{4} ({5}) ({6}) was {7}", m_Counter++, slot.Number, Glfw.GetTime(), (int)key, scancode, GetKeyName(key), GetModsName(mods), GetActioName(state)); } if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.C: { slot.Closeable = !slot.Closeable; Log("(( closing {0} ))", slot.Closeable ? "enabled" : "disabled"); break; } } }
private static void MouseButtonCallback(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods) { var engineWindow = dictionary[window]; if (state == Glfw.InputState.Press || state == Glfw.InputState.Repeat) { engineWindow.MousePressed?.Invoke(engineWindow, new MouseButtonEventArgs() { Button = button, Modifiers = mods }); } else if (state == Glfw.InputState.Release) { engineWindow.MouseReleased?.Invoke(engineWindow, new MouseButtonEventArgs() { Button = button, Modifiers = mods }); } }
private void KeyInput(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState action, Glfw.KeyMods mods) { UpdateKeyStatus((Key)key, action == Glfw.InputState.Press || action == Glfw.InputState.Repeat); }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Escape: { Glfw.SetWindowShouldClose(window, true); break; } case Glfw.KeyCode.NumpadAdd: case Glfw.KeyCode.Up: case Glfw.KeyCode.Q: { SetGamma(window, m_GammaValue + kStepSize); break; } case Glfw.KeyCode.NumpadSubtract: case Glfw.KeyCode.Down: case Glfw.KeyCode.W: { if (m_GammaValue - kStepSize > 0f) { SetGamma(window, m_GammaValue - kStepSize); } break; } } }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state == Glfw.InputState.Press && key == Glfw.KeyCode.Escape) { Glfw.SetWindowShouldClose(window, true); } }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Escape: Glfw.SetWindowShouldClose(window, true); break; case Glfw.KeyCode.Space: m_CurIconColor = (m_CurIconColor + 1) % 5; SetIcon(window, m_CurIconColor); break; case Glfw.KeyCode.X: Glfw.SetWindowIcon(window, null); break; } }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.A: { animateCursor = !animateCursor; if (!animateCursor) { Glfw.SetCursor(window, Glfw.Cursor.None); } break; } case Glfw.KeyCode.Escape: { Glfw.SetWindowShouldClose(window, true); break; } case Glfw.KeyCode.N: { Glfw.SetInputMode(window, Glfw.InputMode.Cursor, Glfw.CursorMode.Normal); Log("(( cursor is normal ))"); break; } case Glfw.KeyCode.D: { Glfw.SetInputMode(window, Glfw.InputMode.Cursor, Glfw.CursorMode.Disabled); Log("(( cursor is disabled ))"); break; } case Glfw.KeyCode.H: { Glfw.SetInputMode(window, Glfw.InputMode.Cursor, Glfw.CursorMode.Hidden); Log("(( cursor is hidden ))"); break; } case Glfw.KeyCode.Space: { swapInterval = 1 - swapInterval; Log("(( swap interval: {0} ))", swapInterval); Glfw.SwapInterval(swapInterval); break; } case Glfw.KeyCode.W: { waitEvents = !waitEvents; Log("(( {0}ing for events ))", waitEvents ? "wait" : "poll"); break; } case Glfw.KeyCode.T: { trackCursor = !trackCursor; break; } case Glfw.KeyCode.Alpha0: { Glfw.SetCursor(window, Glfw.Cursor.None); break; } case Glfw.KeyCode.Alpha1: { Glfw.SetCursor(window, standardCursors[0]); break; } case Glfw.KeyCode.Alpha2: { Glfw.SetCursor(window, standardCursors[1]); break; } case Glfw.KeyCode.Alpha3: { Glfw.SetCursor(window, standardCursors[2]); break; } case Glfw.KeyCode.Alpha4: { Glfw.SetCursor(window, standardCursors[3]); break; } case Glfw.KeyCode.Alpha5: { Glfw.SetCursor(window, standardCursors[4]); break; } case Glfw.KeyCode.Alpha6: { Glfw.SetCursor(window, standardCursors[5]); break; } default: break; } }
private static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { var engineWindow = dictionary[window]; if (state == Glfw.InputState.Press || state == Glfw.InputState.Repeat) { engineWindow.KeyPressed?.Invoke(engineWindow, new KeyEventArgs() { Key = key, ScanCode = scancode, Modifiers = mods }); } else if (state == Glfw.InputState.Release) { engineWindow.KeyReleased?.Invoke(engineWindow, new KeyEventArgs() { Key = key, ScanCode = scancode, Modifiers = mods }); } }
private void handleKeys(Glfw.Window window, Glfw.KeyCode key, int scan, Glfw.KeyAction action, Glfw.KeyMods mods) { if (key == Glfw.KeyCode.Left) { InputEvent(new InputEvent { FootSwitchEvent = new FootSwitchEvent { FootSwitch = FootSwitch.Left, Action = (FootSwitchAction)(int)action // conveniently, the enum values line up. } }); } else if (key == Glfw.KeyCode.Right) { InputEvent(new InputEvent { FootSwitchEvent = new FootSwitchEvent { FootSwitch = FootSwitch.Right, Action = (FootSwitchAction)(int)action // conveniently, the enum values line up. } }); } }
/// <summary> /// The callback method for the keyboard, will set the key from a keycode and a state /// </summary> /// <param name="window"></param> /// <param name="key"></param> /// <param name="scancode"></param> /// <param name="state"></param> /// <param name="mods"></param> private void KeyboardCallBack(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { int keyCode = (int)key; switch (state) { case Glfw.InputState.Repeat: Input.SetKey(keyCode, Input.InputAction.Repeated); break; case Glfw.InputState.Press: Input.SetKey(keyCode, Input.InputAction.Pressed); break; case Glfw.InputState.Release: Input.SetKey(keyCode, Input.InputAction.Released); break; } Debug.Log("Input Keyboard " + key, Debug.DebugLayer.Input, Debug.DebugLevel.Information); }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Space: { Glfw.GetWindowPos(window, out int xpos, out int ypos); Glfw.SetWindowPos(window, xpos, ypos); break; } case Glfw.KeyCode.Escape: { Glfw.SetWindowShouldClose(window, true); break; } default: break; } }
/// <summary> /// The mouse button callback, will set the mouse button from a button and its state /// </summary> /// <param name="window"></param> /// <param name="button"></param> /// <param name="state"></param> /// <param name="mods"></param> private void MouseButtonCallBack(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods) { switch (state) { case Glfw.InputState.Press: Input.SetMouseButton((int)button, Input.InputAction.Pressed); break; case Glfw.InputState.Release: Input.SetMouseButton((int)button, Input.InputAction.Released); break; case Glfw.InputState.Repeat: Input.SetMouseButton((int)button, Input.InputAction.Repeated); break; } Debug.Log("Input Mouse button " + button, Debug.DebugLayer.Input, Debug.DebugLevel.Information); }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Escape: Glfw.SetWindowShouldClose(window, true); break; case Glfw.KeyCode.V: if (mods == Glfw.KeyMods.Control) { string str = Glfw.GetClipboardString(window); if (!string.IsNullOrEmpty(str)) { Log("Clipboard contains \"{0}\"", str); } else { Log("Clipboard does not contain a string"); } } break; case Glfw.KeyCode.C: if (mods == Glfw.KeyMods.Control) { const string str = "Hello GLFW World!"; Glfw.SetClipboardString(window, str); Log("Setting clipboard to \"{0}\"", str); } break; } }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { Log("{0} Key %s", Glfw.GetTime(), state == Glfw.InputState.Press ? "pressed" : "released"); if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.I: Glfw.IconifyWindow(window); break; case Glfw.KeyCode.M: Glfw.MaximizeWindow(window); break; case Glfw.KeyCode.R: Glfw.RestoreWindow(window); break; case Glfw.KeyCode.Escape: Glfw.SetWindowShouldClose(window, true); break; case Glfw.KeyCode.F11: case Glfw.KeyCode.Enter: { if (mods != Glfw.KeyMods.Alt) { return; } if (Glfw.GetWindowMonitor(window)) { Glfw.SetWindowMonitor(window, Glfw.Monitor.None, m_WindowedXPos, m_WindowedYPos, m_WindowedWidth, m_WindowedHeight, 0); } else { var monitor = Glfw.GetPrimaryMonitor(); if (monitor) { var mode = Glfw.GetVideoMode(monitor); Glfw.GetWindowPos(window, out m_WindowedXPos, out m_WindowedYPos); Glfw.GetWindowSize(window, out m_WindowedWidth, out m_WindowedHeight); Glfw.SetWindowMonitor(window, monitor, 0, 0, mode.Width, mode.Height, mode.RefreshRate); } } break; } } }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Space: { Glfw.SetTime(0.0); break; } default: break; } }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Up: { if (swapInterval + 1 > swapInterval) { SetSwapInterval(window, swapInterval + 1); } break; } case Glfw.KeyCode.Down: { if (swapTear) { if (swapInterval - 1 < swapInterval) { SetSwapInterval(window, swapInterval - 1); } } else { if (swapInterval - 1 >= 0) { SetSwapInterval(window, swapInterval - 1); } } break; } case Glfw.KeyCode.Escape: Glfw.SetWindowShouldClose(window, true); break; } }
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods) { if (state != Glfw.InputState.Press) { return; } switch (key) { case Glfw.KeyCode.Q: case Glfw.KeyCode.Escape: Glfw.SetWindowShouldClose(window, true); break; } }
static void MouseButtonCallback(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods) { var slot = m_Slots[window]; Log("{0} to {1} at {2}: Mouse button {3} ({4}) ({5}) was {6}", m_Counter++, slot.Number, Glfw.GetTime(), button, GetButtonName(button), GetModsName(mods), GetActioName(state)); }
private void MouseButtonKeyInput(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods) { Key key = button switch { Glfw.MouseButton.ButtonLeft => Key.MouseKeyLeft, Glfw.MouseButton.ButtonRight => Key.MouseKeyRight, Glfw.MouseButton.Button3 => Key.MouseKeyMiddle, Glfw.MouseButton.Button4 => Key.MouseKey4, Glfw.MouseButton.Button5 => Key.MouseKey5, _ => Key.Unknown }; UpdateKeyStatus(key, state == Glfw.InputState.Press || state == Glfw.InputState.Repeat); }
static NkKeys ConvertToNkKey(Glfw.KeyCode KCode, Glfw.KeyMods Mods) { switch (KCode) { case Glfw.KeyCode.RightShift: case Glfw.KeyCode.LeftShift: return(NkKeys.Shift); case Glfw.KeyCode.LeftControl: case Glfw.KeyCode.RightControl: return(NkKeys.Ctrl); case Glfw.KeyCode.Delete: return(NkKeys.Del); case Glfw.KeyCode.Enter: case Glfw.KeyCode.NumpadEnter: return(NkKeys.Enter); case Glfw.KeyCode.Tab: return(NkKeys.Tab); case Glfw.KeyCode.Backspace: return(NkKeys.Backspace); case Glfw.KeyCode.Up: return(NkKeys.Up); case Glfw.KeyCode.Down: return(NkKeys.Down); case Glfw.KeyCode.Left: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.TextWordLeft); } return(NkKeys.Left); case Glfw.KeyCode.Right: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.TextWordRight); } return(NkKeys.Right); case Glfw.KeyCode.Home: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.TextStart); } return(NkKeys.LineStart); case Glfw.KeyCode.End: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.TextEnd); } return(NkKeys.LineEnd); case Glfw.KeyCode.PageUp: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.ScrollStart); } return(NkKeys.ScrollUp); case Glfw.KeyCode.PageDown: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.ScrollEnd); } return(NkKeys.ScrollDown); case Glfw.KeyCode.A: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.TextSelectAll); } return(NkKeys.None); case Glfw.KeyCode.Z: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.TextUndo); } return(NkKeys.None); case Glfw.KeyCode.Y: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.TextRedo); } return(NkKeys.None); case Glfw.KeyCode.C: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.Copy); } return(NkKeys.None); case Glfw.KeyCode.V: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.Paste); } return(NkKeys.None); case Glfw.KeyCode.X: if (Mods == Glfw.KeyMods.Control) { return(NkKeys.Cut); } return(NkKeys.None); default: return(NkKeys.None); } }