Skip to content

Commit 8af4e4f

Browse files
committed
Keyboard
1 parent 1ff7dba commit 8af4e4f

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

Plugins/CS/Keyboard.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ namespace iOSNativePlugin
99
{
1010
public static class Keyboard
1111
{
12+
static readonly KeyCode[] GCKeyCodeMatch =
13+
{
14+
KeyCode.A, KeyCode.B, KeyCode.C, KeyCode.D, KeyCode.E, KeyCode.F, KeyCode.G, KeyCode.H, KeyCode.I,
15+
KeyCode.J, KeyCode.K, KeyCode.L, KeyCode.M, KeyCode.N, KeyCode.O, KeyCode.P, KeyCode.Q, KeyCode.R,
16+
KeyCode.S, KeyCode.T, KeyCode.U, KeyCode.V, KeyCode.W, KeyCode.X, KeyCode.Y, KeyCode.Z,
17+
//TODO: ...
18+
};
1219
[DllImport("__Internal")] static extern void Keyboard_RegisterKeyPressCallback(LongCallback callback);
1320
[DllImport("__Internal")] static extern void Keyboard_RegisterKeyReleaseCallback(LongCallback callback);
1421
[DllImport("__Internal")] static extern bool Keyboard_IsKeyboardSupported();
@@ -17,29 +24,24 @@ public static class Keyboard
1724
public static event Action<KeyCode> OnKeyPressed;
1825
public static event Action<KeyCode> OnKeyReleased;
1926

27+
[RuntimeInitializeOnLoadMethod]
2028
static void Init()
2129
{
22-
30+
Keyboard_RegisterKeyPressCallback(OnKeyPressedCallback);
31+
Keyboard_RegisterKeyReleaseCallback(OnKeyReleasedCallback);
2332
}
2433

2534
[MonoPInvokeCallback(typeof(LongCallback))]
2635
static void OnKeyPressedCallback(long GCKeyCode)
2736
{
28-
OnKeyPressed?.Invoke();
37+
OnKeyPressed?.Invoke(GCKeyCodeMatch[GCKeyCode]);
2938
}
3039

3140
[MonoPInvokeCallback(typeof(LongCallback))]
3241
static void OnKeyReleasedCallback(long GCKeyCode)
3342
{
34-
OnKeyReleased?.Invoke();
43+
OnKeyReleased?.Invoke(GCKeyCodeMatch[GCKeyCode]);
3544
}
3645

37-
static KeyCode GetKeyCodeFromGCKeyCode(long GCKeyCode)
38-
{
39-
return GCKeyCode switch
40-
{
41-
42-
}
43-
}
4446
}
4547
}

0 commit comments

Comments
 (0)