Compare commits
No commits in common. "87235b8f27c8006860f4063fc66e39b1a63f1751" and "2e2e084233bc1ef42d30f77ee3bbf5bf98e8bb2d" have entirely different histories.
87235b8f27
...
2e2e084233
196
Runtime/Event.cs
196
Runtime/Event.cs
|
@ -3,189 +3,27 @@ using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace SkyHook
|
namespace SkyHook
|
||||||
{
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||||
|
public struct SkyHookEvent
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recorded key updates from SkyHook.
|
/// When the key was pressed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
public readonly ulong Time;
|
||||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
|
||||||
public struct SkyHookEvent
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// When the key's state was updated.
|
|
||||||
/// </summary>
|
|
||||||
public readonly ulong Time;
|
|
||||||
/// <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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The type of <see cref="SkyHookEvent"/>'s event.
|
/// The key is pressed or released
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
public readonly EventType Type;
|
||||||
public enum EventType
|
|
||||||
{
|
|
||||||
KeyPressed,
|
|
||||||
KeyReleased
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The key label identified by native SkyHook.
|
/// The key number that was pressed or released
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
public readonly uint Key;
|
||||||
public enum KeyLabel : ushort
|
}
|
||||||
{
|
|
||||||
Escape,
|
|
||||||
|
|
||||||
// Function Keys
|
public enum EventType
|
||||||
F1,
|
{
|
||||||
F2,
|
KeyPressed,
|
||||||
F3,
|
KeyReleased
|
||||||
F4,
|
}
|
||||||
F5,
|
}
|
||||||
F6,
|
|
||||||
F7,
|
|
||||||
F8,
|
|
||||||
F9,
|
|
||||||
F10,
|
|
||||||
F11,
|
|
||||||
F12,
|
|
||||||
F13,
|
|
||||||
F14,
|
|
||||||
F15,
|
|
||||||
F16,
|
|
||||||
F17,
|
|
||||||
F18,
|
|
||||||
F19,
|
|
||||||
F20,
|
|
||||||
F21,
|
|
||||||
F22,
|
|
||||||
F23,
|
|
||||||
F24,
|
|
||||||
|
|
||||||
// 2nd Layer
|
|
||||||
Grave,
|
|
||||||
Alpha1,
|
|
||||||
Alpha2,
|
|
||||||
Alpha3,
|
|
||||||
Alpha4,
|
|
||||||
Alpha5,
|
|
||||||
Alpha6,
|
|
||||||
Alpha7,
|
|
||||||
Alpha8,
|
|
||||||
Alpha9,
|
|
||||||
Alpha0,
|
|
||||||
Minus,
|
|
||||||
Equal,
|
|
||||||
Backspace,
|
|
||||||
|
|
||||||
// 3rd Layer
|
|
||||||
Tab,
|
|
||||||
Q,
|
|
||||||
W,
|
|
||||||
E,
|
|
||||||
R,
|
|
||||||
T,
|
|
||||||
Y,
|
|
||||||
U,
|
|
||||||
I,
|
|
||||||
O,
|
|
||||||
P,
|
|
||||||
LeftBrace,
|
|
||||||
RightBrace,
|
|
||||||
BackSlash,
|
|
||||||
|
|
||||||
// 4th Layer
|
|
||||||
CapsLock,
|
|
||||||
A,
|
|
||||||
S,
|
|
||||||
D,
|
|
||||||
F,
|
|
||||||
G,
|
|
||||||
H,
|
|
||||||
J,
|
|
||||||
K,
|
|
||||||
L,
|
|
||||||
Semicolon,
|
|
||||||
Apostrophe,
|
|
||||||
Enter,
|
|
||||||
|
|
||||||
// 5th Layer
|
|
||||||
LShift,
|
|
||||||
Z,
|
|
||||||
X,
|
|
||||||
C,
|
|
||||||
V,
|
|
||||||
B,
|
|
||||||
N,
|
|
||||||
M,
|
|
||||||
Comma,
|
|
||||||
Dot,
|
|
||||||
Slash,
|
|
||||||
RShift,
|
|
||||||
|
|
||||||
// 6th Layer
|
|
||||||
LControl,
|
|
||||||
Super,
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,15 +2,8 @@ using System;
|
||||||
|
|
||||||
namespace SkyHook
|
namespace SkyHook
|
||||||
{
|
{
|
||||||
/// <summary>
|
public class SkyHookException : Exception
|
||||||
/// An <see cref="Exception"/> that specifically occurred in SkyHook.
|
{
|
||||||
/// </summary>
|
public SkyHookException(string message) : base(message) { }
|
||||||
public class SkyHookException : Exception
|
}
|
||||||
{
|
}
|
||||||
/// <summary>
|
|
||||||
/// Initializes an instance of <see cref="SkyHookException"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">A message to pass along with exception.</param>
|
|
||||||
public SkyHookException(string message) : base(message) { }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +1,34 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
namespace SkyHook
|
namespace SkyHook
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Manages SkyHook activity.
|
|
||||||
/// A "<see cref="GameObject.DontDestroyOnLoad"/>ed" instance will be created automatically upon use.
|
|
||||||
/// </summary>
|
|
||||||
public class SkyHookManager : MonoBehaviour
|
public class SkyHookManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
private static SkyHookManager _instance;
|
private static SkyHookManager _instance;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether this process is focused.
|
|
||||||
/// </summary>
|
|
||||||
public static bool IsFocused;
|
public static bool IsFocused;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or the event will be received only if the game window is focused.
|
/// Whether or not the event will be received only if the game window is focused.
|
||||||
/// Note that only down key events will be ignored.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// ReSharper disable once MemberCanBePrivate.Global
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
// ReSharper disable once FieldCanBeMadeReadOnly.Global
|
// ReSharper disable once FieldCanBeMadeReadOnly.Global
|
||||||
public bool requireFocus = true;
|
public bool requireFocus = true;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether the hook is active now.
|
|
||||||
/// </summary>
|
|
||||||
public bool isHookActive;
|
public bool isHookActive;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Your callback for each key updated events.
|
/// The key updated event data
|
||||||
/// Use <see cref="UnityEvent.AddListener"/> to register your callback.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// ReSharper disable once MemberCanBePrivate.Global
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public static readonly UnityEvent<SkyHookEvent> KeyUpdated = new();
|
public static readonly UnityEvent<SkyHookEvent> KeyUpdated = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The instance of <see cref="SkyHookManager"/>.
|
/// The instance of sky hook manager. The instance will be created if it does not exist
|
||||||
/// A new instance will be created if it does not exist.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// ReSharper disable once MemberCanBePrivate.Global
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public static SkyHookManager Instance
|
public static SkyHookManager Instance
|
||||||
|
@ -117,17 +105,11 @@ namespace SkyHook
|
||||||
isHookActive = false;
|
isHookActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Starts the native hook.
|
|
||||||
/// </summary>
|
|
||||||
public static void StartHook()
|
public static void StartHook()
|
||||||
{
|
{
|
||||||
Instance._StartHook();
|
Instance._StartHook();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Stops the native hook.
|
|
||||||
/// </summary>
|
|
||||||
public static void StopHook()
|
public static void StopHook()
|
||||||
{
|
{
|
||||||
Instance._StopHook();
|
Instance._StopHook();
|
||||||
|
@ -146,4 +128,4 @@ namespace SkyHook
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,31 +2,16 @@ using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace SkyHook
|
namespace SkyHook
|
||||||
{
|
{
|
||||||
/// <summary>
|
internal static class SkyHookNative
|
||||||
/// Native method calls for SkyHook.
|
{
|
||||||
/// </summary>
|
public delegate void Callback(SkyHookEvent ev);
|
||||||
internal static class SkyHookNative
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The native callback handled by <see cref="SkyHookManager"/>.
|
|
||||||
/// </summary>
|
|
||||||
public delegate void Callback(SkyHookEvent ev);
|
|
||||||
|
|
||||||
private const string Lib = "skyhook";
|
private const string Lib = "skyhook";
|
||||||
|
|
||||||
/// <summary>
|
[DllImport(Lib, EntryPoint = "start_hook", CallingConvention = CallingConvention.Cdecl)]
|
||||||
/// The native version of <see cref="SkyHookManager.StartHook"/> method handled by <see cref="SkyHookManager"/>.
|
public static extern string StartHook(Callback callback);
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A native callback.</param>
|
|
||||||
/// <returns><c>null</c> if no error, or an error message.</returns>
|
|
||||||
[DllImport(Lib, EntryPoint = "start_hook", CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
public static extern string StartHook(Callback callback);
|
|
||||||
|
|
||||||
/// <summary>
|
[DllImport(Lib, EntryPoint = "stop_hook", CallingConvention = CallingConvention.Cdecl)]
|
||||||
/// The native version of <see cref="SkyHookManager.StopHook"/> method handled by <see cref="SkyHookManager"/>.
|
public static extern string StopHook();
|
||||||
/// </summary>
|
}
|
||||||
/// <returns><c>null</c> if no error, or an error message.</returns>
|
}
|
||||||
[DllImport(Lib, EntryPoint = "stop_hook", CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
public static extern string StopHook();
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Reference in New Issue