-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShiftKeys.cs
More file actions
91 lines (79 loc) · 4.68 KB
/
ShiftKeys.cs
File metadata and controls
91 lines (79 loc) · 4.68 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BookmarksModNS
{
internal class ShiftKeys
{
public enum Result { None, Meta, OtherMetas };
public static ModifierKey defaultMode = ModifierKey.SHIFT;
public static Result TestShiftStatus(InputController controller)
{
return GetTest(defaultMode)(controller);
}
private static Func<InputController, Result> pcShiftCheck = delegate (InputController controller) {
if (controller.GetKey(Key.LeftAlt) || controller.GetKey(Key.RightAlt) ||
controller.GetKey(Key.LeftWindows) || controller.GetKey(Key.RightWindows) ||
controller.GetKey(Key.LeftCtrl) || controller.GetKey(Key.RightCtrl)) return Result.OtherMetas;
if (controller.GetKey(Key.LeftShift) || controller.GetKey(Key.RightShift)) return Result.Meta;
return Result.None;
};
private static Func<InputController, Result> macShiftCheck = delegate (InputController controller) {
if (controller.GetKey(Key.LeftApple) || controller.GetKey(Key.RightApple) ||
controller.GetKey(Key.LeftCtrl) || controller.GetKey(Key.RightCtrl) ||
controller.GetKey(Key.LeftCommand) || controller.GetKey(Key.RightCommand)) return Result.OtherMetas;
if (controller.GetKey(Key.LeftShift) || controller.GetKey(Key.RightShift)) return Result.Meta;
return Result.None;
};
private static Func<InputController, Result> pcControlCheck = delegate (InputController controller) {
if (controller.GetKey(Key.LeftAlt) || controller.GetKey(Key.RightAlt) ||
controller.GetKey(Key.LeftWindows) || controller.GetKey(Key.RightWindows) ||
controller.GetKey(Key.LeftShift) || controller.GetKey(Key.RightShift)) return Result.OtherMetas;
if (controller.GetKey(Key.LeftCtrl) || controller.GetKey(Key.RightCtrl)) return Result.Meta;
return Result.None;
};
private static Func<InputController, Result> macCommandCheck = delegate (InputController controller) {
if (controller.GetKey(Key.LeftApple) || controller.GetKey(Key.RightApple) ||
controller.GetKey(Key.LeftCtrl) || controller.GetKey(Key.RightCtrl) ||
controller.GetKey(Key.LeftShift) || controller.GetKey(Key.RightShift)) return Result.OtherMetas;
if (controller.GetKey(Key.LeftCommand) || controller.GetKey(Key.RightCommand)) return Result.Meta;
return Result.None;
};
private static Func<InputController, Result> pcAltCheck = delegate (InputController controller) {
if (controller.GetKey(Key.LeftCtrl) || controller.GetKey(Key.RightCtrl) ||
controller.GetKey(Key.LeftWindows) || controller.GetKey(Key.RightWindows) ||
controller.GetKey(Key.LeftShift) || controller.GetKey(Key.RightShift)) return Result.OtherMetas;
if (controller.GetKey(Key.LeftAlt) || controller.GetKey(Key.RightAlt)) return Result.Meta;
return Result.None;
};
private static Func<InputController, Result> macAltCheck = delegate(InputController controller) {
if (controller.GetKey(Key.LeftApple) || controller.GetKey(Key.RightApple) ||
controller.GetKey(Key.LeftCtrl) || controller.GetKey(Key.RightCtrl) ||
controller.GetKey(Key.LeftShift) || controller.GetKey(Key.RightShift)) return Result.OtherMetas;
if (controller.GetKey(Key.LeftAlt) || controller.GetKey(Key.RightAlt)) return Result.Meta;
return Result.None;
};
private static Func<InputController, Result> cachedFunc;
private static ModifierKey cachedMode;
private static Func<InputController, Result> GetTest(ModifierKey meta)
{
if (cachedFunc == null || cachedMode != meta)
{
RuntimePlatform platform = Application.platform;
cachedFunc = meta switch
{
ModifierKey.SHIFT => platform == RuntimePlatform.WindowsPlayer ? pcShiftCheck : macShiftCheck,
ModifierKey.CONTROL => platform == RuntimePlatform.WindowsPlayer ? pcControlCheck : macCommandCheck,
ModifierKey.ALT => platform == RuntimePlatform.WindowsPlayer ? pcAltCheck : macAltCheck,
_ => pcShiftCheck,
};
cachedMode = meta;
//BookmarksMod.instance.Log($"ShiftKeys set {cachedMode} {cachedFunc}");
}
return cachedFunc;
}
public static void Reset() { cachedFunc = null; }
}
}