2022-12-08 00:35:43 +09:00
|
|
|
using System;
|
2022-11-03 21:18:05 +09:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2022-11-03 20:55:22 +09:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace SkyHook
|
|
|
|
{
|
2022-11-03 21:18:05 +09:00
|
|
|
/// <summary>
|
2022-11-06 22:46:39 +09:00
|
|
|
/// Recorded key updates from SkyHook.
|
2022-11-03 21:18:05 +09:00
|
|
|
/// </summary>
|
2022-11-06 22:46:39 +09:00
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
2022-12-08 00:35:43 +09:00
|
|
|
public readonly struct SkyHookEvent
|
2022-11-06 22:46:39 +09:00
|
|
|
{
|
2022-12-08 00:35:43 +09:00
|
|
|
/// <summary>
|
|
|
|
/// Epoch ticks to append in <see cref="GetTimeInTicks"/>.
|
|
|
|
/// </summary>
|
|
|
|
private static readonly long EpochTicks = new DateTime(1970, 1, 1).Ticks;
|
|
|
|
|
2022-11-06 22:46:39 +09:00
|
|
|
/// <summary>
|
2022-12-08 00:21:21 +09:00
|
|
|
/// Precise time of the key's state update in seconds.
|
2022-11-06 22:46:39 +09:00
|
|
|
/// </summary>
|
2022-12-08 00:21:21 +09:00
|
|
|
public readonly long TimeSec;
|
2022-12-01 16:08:37 +09:00
|
|
|
/// <summary>
|
2022-12-08 00:21:21 +09:00
|
|
|
/// Precise time of the key's state update but only contains nanoseconds.
|
2022-12-01 16:08:37 +09:00
|
|
|
/// </summary>
|
2022-12-08 00:21:21 +09:00
|
|
|
public readonly uint TimeSubsecNano;
|
2022-11-06 22:46:39 +09:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the key is pressed or released.
|
|
|
|
/// </summary>
|
|
|
|
public readonly EventType Type;
|
|
|
|
/// <summary>
|
|
|
|
/// The identified key label from the native assembly.
|
|
|
|
/// </summary>
|
|
|
|
public readonly KeyLabel Label;
|
|
|
|
/// <summary>
|
|
|
|
/// The key number that was pressed or released.
|
|
|
|
/// </summary>
|
|
|
|
public readonly ushort Key;
|
2022-12-08 00:35:43 +09:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the sum of <see cref="TimeSec"/> and <see cref="TimeSubsecNano"/> in ticks.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The sum of <see cref="TimeSec"/> and <see cref="TimeSubsecNano"/> in ticks.</returns>
|
|
|
|
public long GetTimeInTicks()
|
|
|
|
=> (TimeSec * 10000000) + (TimeSubsecNano / 100) + EpochTicks;
|
2022-11-06 22:46:39 +09:00
|
|
|
}
|
|
|
|
|
2022-11-03 21:18:05 +09:00
|
|
|
/// <summary>
|
2022-11-06 22:46:39 +09:00
|
|
|
/// The type of <see cref="SkyHookEvent"/>'s event.
|
2022-11-03 21:18:05 +09:00
|
|
|
/// </summary>
|
2022-11-06 22:46:39 +09:00
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
|
|
|
public enum EventType
|
|
|
|
{
|
|
|
|
KeyPressed,
|
|
|
|
KeyReleased
|
|
|
|
}
|
|
|
|
|
2022-11-06 22:11:11 +09:00
|
|
|
/// <summary>
|
2022-11-06 22:46:39 +09:00
|
|
|
/// The key label identified by native SkyHook.
|
|
|
|
/// This label will be the same regardless of what OS the player is in.
|
|
|
|
/// <br/>
|
|
|
|
/// This is a direct import of the https://git.pikokr.dev/SkyHook/SkyHook/src/branch/main/skyhook/src/keycodes.rs native enum.
|
2022-11-06 22:11:11 +09:00
|
|
|
/// </summary>
|
2022-11-06 22:46:39 +09:00
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
|
|
|
public enum KeyLabel : ushort
|
|
|
|
{
|
|
|
|
Escape,
|
|
|
|
|
|
|
|
// Function Keys
|
|
|
|
F1,
|
|
|
|
F2,
|
|
|
|
F3,
|
|
|
|
F4,
|
|
|
|
F5,
|
|
|
|
F6,
|
|
|
|
F7,
|
|
|
|
F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
LAlt,
|
|
|
|
Space,
|
|
|
|
RAlt,
|
|
|
|
RControl,
|
|
|
|
|
|
|
|
// Controls
|
|
|
|
PrintScreen,
|
|
|
|
ScrollLock,
|
|
|
|
PauseBreak,
|
|
|
|
Insert,
|
|
|
|
Home,
|
|
|
|
PageUp,
|
|
|
|
Delete,
|
|
|
|
End,
|
|
|
|
PageDown,
|
|
|
|
ArrowUp,
|
|
|
|
ArrowLeft,
|
|
|
|
ArrowDown,
|
|
|
|
ArrowRight,
|
|
|
|
|
|
|
|
// Keypad
|
|
|
|
NumLock,
|
|
|
|
KeypadSlash,
|
|
|
|
KeypadAsterisk,
|
|
|
|
KeypadMinus,
|
|
|
|
Keypad1,
|
|
|
|
Keypad2,
|
|
|
|
Keypad3,
|
|
|
|
Keypad4,
|
|
|
|
Keypad5,
|
|
|
|
Keypad6,
|
|
|
|
Keypad7,
|
|
|
|
Keypad8,
|
|
|
|
Keypad9,
|
|
|
|
Keypad0,
|
|
|
|
KeypadDot,
|
|
|
|
KeypadPlus,
|
|
|
|
KeypadEnter,
|
|
|
|
|
|
|
|
// Mouse
|
|
|
|
MouseLeft,
|
|
|
|
MouseRight,
|
|
|
|
MouseMiddle,
|
|
|
|
MouseX1,
|
|
|
|
MouseX2,
|
|
|
|
|
|
|
|
// Uncategorized
|
|
|
|
Unknown
|
|
|
|
}
|
2022-11-06 22:47:16 +09:00
|
|
|
}
|