Last active
October 26, 2020 13:37
-
-
Save leezer3/0a9106a3f612c48ec7b33d853176e3a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Win32; | |
using OpenTK; | |
using OpenTK.Input; | |
namespace TestProgram | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
ToolkitOptions options = new ToolkitOptions(); | |
options.Backend = PlatformBackend.PreferX11; | |
Toolkit.Init(options); | |
TestWindow window = new TestWindow(); | |
window.Run(); | |
} | |
} | |
class TestWindow : GameWindow | |
{ | |
internal TestWindow() : base() | |
{ | |
KeyUp += KeyUpEvent; | |
KeyDown += KeyDownEvent; | |
SystemEvents.SessionSwitch += (SessionSwitch); | |
} | |
protected override void OnUpdateFrame(FrameEventArgs e) | |
{ | |
KeyboardState state = Keyboard.GetState(); | |
} | |
internal void KeyDownEvent(object sender, KeyboardKeyEventArgs keyboardKeyEventArgs) | |
{ | |
Console.WriteLine(keyboardKeyEventArgs.Key + " pressed"); | |
} | |
internal void KeyUpEvent(object sender, KeyboardKeyEventArgs keyboardKeyEventArgs) | |
{ | |
Console.WriteLine(keyboardKeyEventArgs.Key + " released"); | |
} | |
private void SessionSwitch(object sender, SessionSwitchEventArgs e) | |
{ | |
KeyboardState state = Keyboard.GetState(); | |
if (e.Reason == SessionSwitchReason.SessionLock) | |
{ | |
if (state.IsAnyKeyDown) | |
{ | |
Console.WriteLine("Locked, the following keys are down:"); | |
for (Key key = 0; key < Key.LastKey; key++) | |
{ | |
if (state.IsKeyDown(key)) | |
{ | |
Console.WriteLine(key + " is down"); | |
} | |
} | |
} | |
} | |
if (e.Reason == SessionSwitchReason.SessionUnlock) | |
{ | |
Console.WriteLine("Unlocked, the following keys are down:"); | |
for (Key key = 0; key < Key.LastKey; key++) | |
{ | |
if (state.IsKeyDown(key)) | |
{ | |
Console.WriteLine(key + " is down"); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment