Compare commits
No commits in common. "87235b8f27c8006860f4063fc66e39b1a63f1751" and "2e2e084233bc1ef42d30f77ee3bbf5bf98e8bb2d" have entirely different histories.
87235b8f27
...
2e2e084233
170
Runtime/Event.cs
170
Runtime/Event.cs
|
@ -3,189 +3,27 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace SkyHook
|
||||
{
|
||||
/// <summary>
|
||||
/// Recorded key updates from SkyHook.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public struct SkyHookEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// When the key's state was updated.
|
||||
/// When the key was pressed
|
||||
/// </summary>
|
||||
public readonly ulong Time;
|
||||
/// <summary>
|
||||
/// Whether the key is pressed or released.
|
||||
/// The key is pressed or released
|
||||
/// </summary>
|
||||
public readonly EventType Type;
|
||||
/// <summary>
|
||||
/// The identified key label from the native assembly.
|
||||
/// The key number that was pressed or released
|
||||
/// </summary>
|
||||
public readonly KeyLabel Label;
|
||||
/// <summary>
|
||||
/// The key number that was pressed or released.
|
||||
/// </summary>
|
||||
public readonly ushort Key;
|
||||
public readonly uint Key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The type of <see cref="SkyHookEvent"/>'s event.
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||
public enum EventType
|
||||
{
|
||||
KeyPressed,
|
||||
KeyReleased
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||
public enum KeyLabel : ushort
|
||||
{
|
||||
Escape,
|
||||
|
||||
// Function Keys
|
||||
F1,
|
||||
F2,
|
||||
F3,
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="Exception"/> that specifically occurred in SkyHook.
|
||||
/// </summary>
|
||||
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.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace SkyHook
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages SkyHook activity.
|
||||
/// A "<see cref="GameObject.DontDestroyOnLoad"/>ed" instance will be created automatically upon use.
|
||||
/// </summary>
|
||||
public class SkyHookManager : MonoBehaviour
|
||||
{
|
||||
private static SkyHookManager _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this process is focused.
|
||||
/// </summary>
|
||||
public static bool IsFocused;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or the event will be received only if the game window is focused.
|
||||
/// Note that only down key events will be ignored.
|
||||
/// Whether or not the event will be received only if the game window is focused.
|
||||
/// </summary>
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
// ReSharper disable once FieldCanBeMadeReadOnly.Global
|
||||
public bool requireFocus = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the hook is active now.
|
||||
/// </summary>
|
||||
public bool isHookActive;
|
||||
|
||||
/// <summary>
|
||||
/// Your callback for each key updated events.
|
||||
/// Use <see cref="UnityEvent.AddListener"/> to register your callback.
|
||||
/// The key updated event data
|
||||
/// </summary>
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public static readonly UnityEvent<SkyHookEvent> KeyUpdated = new();
|
||||
|
||||
/// <summary>
|
||||
/// The instance of <see cref="SkyHookManager"/>.
|
||||
/// A new instance will be created if it does not exist.
|
||||
/// The instance of sky hook manager. The instance will be created if it does not exist
|
||||
/// </summary>
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public static SkyHookManager Instance
|
||||
|
@ -117,17 +105,11 @@ namespace SkyHook
|
|||
isHookActive = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the native hook.
|
||||
/// </summary>
|
||||
public static void StartHook()
|
||||
{
|
||||
Instance._StartHook();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the native hook.
|
||||
/// </summary>
|
||||
public static void StopHook()
|
||||
{
|
||||
Instance._StopHook();
|
||||
|
|
|
@ -2,30 +2,15 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace SkyHook
|
||||
{
|
||||
/// <summary>
|
||||
/// Native method calls for SkyHook.
|
||||
/// </summary>
|
||||
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";
|
||||
|
||||
/// <summary>
|
||||
/// The native version of <see cref="SkyHookManager.StartHook"/> method handled by <see cref="SkyHookManager"/>.
|
||||
/// </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>
|
||||
/// The native version of <see cref="SkyHookManager.StopHook"/> method handled by <see cref="SkyHookManager"/>.
|
||||
/// </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