Compare commits
5 Commits
2e2e084233
...
87235b8f27
Author | SHA1 | Date |
---|---|---|
CrackThrough | 87235b8f27 | |
CrackThrough | 7eae03362b | |
CrackThrough | 06407c97a1 | |
CrackThrough | 58581a7c53 | |
CrackThrough | 9d97a7ce72 |
202
Runtime/Event.cs
202
Runtime/Event.cs
|
@ -3,27 +3,189 @@ using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace SkyHook
|
namespace SkyHook
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
|
||||||
public struct SkyHookEvent
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When the key was pressed
|
/// Recorded key updates from SkyHook.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly ulong Time;
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
/// <summary>
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||||
/// The key is pressed or released
|
public struct SkyHookEvent
|
||||||
/// </summary>
|
{
|
||||||
public readonly EventType Type;
|
/// <summary>
|
||||||
/// <summary>
|
/// When the key's state was updated.
|
||||||
/// The key number that was pressed or released
|
/// </summary>
|
||||||
/// </summary>
|
public readonly ulong Time;
|
||||||
public readonly uint Key;
|
/// <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;
|
||||||
|
}
|
||||||
|
|
||||||
public enum EventType
|
/// <summary>
|
||||||
{
|
/// The type of <see cref="SkyHookEvent"/>'s event.
|
||||||
KeyPressed,
|
/// </summary>
|
||||||
KeyReleased
|
[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,8 +2,15 @@ using System;
|
||||||
|
|
||||||
namespace SkyHook
|
namespace SkyHook
|
||||||
{
|
{
|
||||||
public class SkyHookException : Exception
|
/// <summary>
|
||||||
{
|
/// An <see cref="Exception"/> that specifically occurred in SkyHook.
|
||||||
public SkyHookException(string message) : base(message) { }
|
/// </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,34 +1,46 @@
|
||||||
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 not the event will be received only if the game window is focused.
|
/// Whether or 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>
|
||||||
/// The key updated event data
|
/// Your callback for each key updated events.
|
||||||
|
/// 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 sky hook manager. The instance will be created if it does not exist
|
/// The instance of <see cref="SkyHookManager"/>.
|
||||||
|
/// 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
|
||||||
|
@ -105,11 +117,17 @@ 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();
|
||||||
|
|
|
@ -2,16 +2,31 @@ using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace SkyHook
|
namespace SkyHook
|
||||||
{
|
{
|
||||||
internal static class SkyHookNative
|
/// <summary>
|
||||||
{
|
/// Native method calls for SkyHook.
|
||||||
public delegate void Callback(SkyHookEvent ev);
|
/// </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";
|
private const string Lib = "skyhook";
|
||||||
|
|
||||||
[DllImport(Lib, EntryPoint = "start_hook", CallingConvention = CallingConvention.Cdecl)]
|
/// <summary>
|
||||||
public static extern string StartHook(Callback callback);
|
/// 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);
|
||||||
|
|
||||||
[DllImport(Lib, EntryPoint = "stop_hook", CallingConvention = CallingConvention.Cdecl)]
|
/// <summary>
|
||||||
public static extern string StopHook();
|
/// 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