Skip to content

Commit ece6174

Browse files
committed
开发iOS键盘支持(未完工)
1 parent 8b7567a commit ece6174

4 files changed

Lines changed: 160 additions & 0 deletions

File tree

Plugins/Native/Headers/Input.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "../Utils.mm"
2+
#import <GameController/GameController.h>
3+
@interface Input : NSObject
4+
5+
@end

Plugins/Native/Headers/Input.h.meta

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#import "../Headers/Input.h"
2+
3+
4+
@implementation Input
5+
static BOOL inited;
6+
API_AVAILABLE(ios(14.0)) static GCKeyboard* keyboard;
7+
NSMutableSet *pressedKeys;
8+
9+
+(void)Init
10+
{
11+
if(inited)
12+
return;
13+
if (@available(iOS 14.0, *)) {
14+
keyboard = GCKeyboard.coalescedKeyboard;
15+
pressedKeys = [NSMutableSet init];
16+
[[NSNotificationCenter defaultCenter] addObserver:[Input class]
17+
selector:@selector(OnKeyboardConnected:)
18+
name:GCKeyboardDidConnectNotification
19+
object:nil];
20+
[[NSNotificationCenter defaultCenter] addObserver:[Input class]
21+
selector:@selector(OnKeyboardDisconnected:)
22+
name:GCKeyboardDidDisconnectNotification
23+
object:nil];
24+
}
25+
inited = YES;
26+
}
27+
28+
+(void)OnKeyboardConnected:(NSNotification *)notification
29+
{
30+
if (@available(iOS 14.0, *)) {
31+
keyboard = notification.object;
32+
keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput * _Nonnull keyboard, GCControllerButtonInput * _Nonnull key, GCKeyCode keyCode, BOOL pressed)
33+
{
34+
NSNumber *KeyCodeNumber = [NSNumber numberWithLong:keyCode];
35+
if(pressed){
36+
[pressedKeys addObject:KeyCodeNumber];
37+
}
38+
else{
39+
[pressedKeys removeObject:KeyCodeNumber];
40+
}
41+
};
42+
}
43+
}
44+
45+
+(void)OnKeyboardDisconnected:(NSNotification *)notification
46+
{
47+
if (@available(iOS 14.0, *)) {
48+
49+
if(keyboard != nil)
50+
keyboard.keyboardInput.keyChangedHandler = nil;
51+
keyboard = nil;
52+
53+
}
54+
}
55+
56+
+(BOOL)IsKeyboardSupported
57+
{
58+
if (@available(iOS 14.0, *))
59+
{
60+
[Input Init];
61+
return keyboard != nil;
62+
} else {
63+
return NO;
64+
}
65+
66+
}
67+
68+
+(BOOL)IsAnyKeyPressed
69+
{
70+
if (@available(iOS 14.0, *))
71+
{
72+
[Input Init];
73+
return keyboard.keyboardInput.anyKeyPressed;
74+
} else {
75+
return false;
76+
}
77+
}
78+
79+
+(BOOL)GetKey:(GCKeyCode)keyCode
80+
API_AVAILABLE(ios(14.0))
81+
{
82+
if (@available(iOS 14.0, *)){
83+
[Input Init];
84+
NSNumber *KeyCodeNumber = [NSNumber numberWithLong:keyCode];
85+
return [pressedKeys containsObject:KeyCodeNumber];
86+
}
87+
return NO;
88+
89+
}
90+
91+
@end

Plugins/Native/Implementations/Input.mm.meta

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)