-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
HookArgs.cs
68 lines (60 loc) · 1.94 KB
/
HookArgs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using UnityEngine;
namespace UnityRawInput
{
[StructLayout(LayoutKind.Sequential)]
public struct KeyboardArgs
{
public uint Code;
public uint ScanCode;
public KeyboardFlags Flags;
public uint Time;
public UIntPtr ExtraInfo;
public uint TrueScanCode => Flags.HasFlag(KeyboardFlags.Extended) ? ScanCode + 0x100 : ScanCode;
public uint Advanced => TrueScanCode << 8;
public uint Hybrid => Code + Advanced;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator KeyboardArgs (IntPtr ptr)
=> Marshal.PtrToStructure<KeyboardArgs>(ptr);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator RawKey (KeyboardArgs args)
{
if (Enum.IsDefined(typeof(RawKey), args.Code))
return (RawKey)args.Code;
if (Enum.IsDefined(typeof(RawKey), args.Advanced))
return (RawKey)args.Advanced;
if (Enum.IsDefined(typeof(RawKey), args.Hybrid))
return (RawKey)args.Hybrid;
return (RawKey)args.Code;
}
}
[Flags]
public enum KeyboardFlags : uint
{
Extended = 0x01,
LowerInjected = 0x02,
Injected = 0x10,
AltDown = 0x20,
Up = 0x80
}
[StructLayout(LayoutKind.Sequential)]
public struct MouseArgs
{
public Vector2Int Point;
public uint MouseData;
public MouseFlags Flags;
public uint Time;
public UIntPtr ExtraInfo;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator MouseArgs (IntPtr ptr)
=> Marshal.PtrToStructure<MouseArgs>(ptr);
}
[Flags]
public enum MouseFlags : uint
{
Injected = 0x01,
LowerInjected = 0x02
}
}