Permalink
Browse files

add support for smart keyboard

  • Loading branch information...
imxieyi committed Sep 4, 2017
1 parent d23b438 commit f0ba66fcd637325b1cc36d121e93a754624b079c
View
@@ -0,0 +1,20 @@
//
// PPSSPPUIApplication.h
// PPSSPP
//
// Created by xieyi on 2017/9/4.
//
//
#ifndef PPSSPPUIApplication_h
#define PPSSPPUIApplication_h
#import <UIKit/UIKit.h>
@interface PPSSPPUIApplication : UIApplication
{
}
@end
#endif /* PPSSPPUIApplication_h */
View
@@ -0,0 +1,114 @@
//
// PPSSPPUIApplication.m
// PPSSPP
//
// Created by xieyi on 2017/9/4.
//
//
#import "PPSSPPUIApplication.h"
#import <Foundation/Foundation.h>
#import <Foundation/NSObjCRuntime.h>
#import <GLKit/GLKit.h>
#include "base/display.h"
#include "base/timeutil.h"
#include "file/zip_read.h"
#include "input/input_state.h"
#include "net/resolve.h"
#include "ui/screen.h"
#include "thin3d/thin3d.h"
#include "input/keycodes.h"
#include "gfx_es2/gpu_features.h"
#import "ios/AppDelegate.h"
#include "ios/SmartKeyboardMap.hpp"
#include "Core/Config.h"
#include "Common/GraphicsContext.h"
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/machine.h>
#ifndef IS_IOS7
#define IS_IOS7 ([[UIDevice currentDevice].systemVersion floatValue]>=7.0)
#endif
#ifndef IS_IOS9
#define IS_IOS9 ([[UIDevice currentDevice].systemVersion floatValue]>=9.0)
#endif
#define IS_64BIT (sizeof(NSUInteger)==8)
#define GSEVENT_TYPE 2
#define GSEVENT_FLAGS (IS_64BIT?10:12)
#define GSEVENTKEY_KEYCODE (IS_64BIT?(IS_IOS9?13:19):(IS_IOS7?17:15))
#define GSEVENT_TYPE_KEYUP 11
#define GSEVENT_TYPE_KEYDOWN 10
#define GSEVENT_TYPE_MODIFIER 12
#define GSEVENT_FLAG_LCMD 65536 // 0x00010000
#define GSEVENT_FLAG_LSHIFT 131072 // 0x00020000
#define GSEVENT_FLAG_LCTRL 1048576 // 0x00100000
#define GSEVENT_FLAG_LALT 524288 // 0x00080000
#define GSEVENT_FLAG_RSHIFT 2097152 // 0x00200000 - not sent IOS9
#define GSEVENT_FLAG_RCTRL 8388608 // 0x00800000 - not sent IOS9
#define GSEVENT_FLAG_RALT 4194304 // 0x00400000 - not sent IOS9
@implementation PPSSPPUIApplication
- (instancetype)init {
auto instance = [super init];
instance.delegate = [[AppDelegate alloc] init];
return instance;
}
- (void)decodeKeyEvent:(NSInteger *)eventMem {
NSInteger eventType = eventMem[GSEVENT_TYPE];
NSInteger eventScanCode = eventMem[GSEVENTKEY_KEYCODE];
//NSLog(@"Got key: %d", (int)eventScanCode);
if (eventType == GSEVENT_TYPE_KEYUP) {
struct KeyInput key;
key.flags = KEY_UP;
key.keyCode = getSmartKeyboardMap((int)eventScanCode);
key.deviceId = DEVICE_ID_KEYBOARD;
NativeKey(key);
} else if (GSEVENT_TYPE_KEYDOWN) {
struct KeyInput key;
key.flags = KEY_DOWN;
key.keyCode = getSmartKeyboardMap((int)eventScanCode);
key.deviceId = DEVICE_ID_KEYBOARD;
NativeKey(key);
}
}
- (void)handleKeyUIEvent:(UIEvent *) event {
if ([event respondsToSelector:@selector(_gsEvent)]) {
NSInteger *eventMem;
eventMem = (NSInteger *) (__bridge void*)[event performSelector:@selector(_gsEvent)];
if (eventMem) {
[self decodeKeyEvent:eventMem];
}
}
}
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
if ([event respondsToSelector:@selector(_gsEvent)]) {
NSInteger *eventMem;
eventMem = (NSInteger *) (__bridge void*)[event performSelector:@selector(_gsEvent)];
if (eventMem) {
[self decodeKeyEvent:eventMem];
}
}
}
@end
View
@@ -0,0 +1,78 @@
//
// SmartKeyboardMap.cpp
// PPSSPP
//
// Created by xieyi on 2017/9/4.
//
//
#include "SmartKeyboardMap.hpp"
#include "input/keycodes.h"
int getSmartKeyboardMap(int keycode) {
switch(keycode) {
case 4: return NKCODE_A;
case 5: return NKCODE_B;
case 6: return NKCODE_C;
case 7: return NKCODE_D;
case 8: return NKCODE_E;
case 9: return NKCODE_F;
case 10: return NKCODE_G;
case 11: return NKCODE_H;
case 12: return NKCODE_I;
case 13: return NKCODE_J;
case 14: return NKCODE_K;
case 15: return NKCODE_L;
case 16: return NKCODE_M;
case 17: return NKCODE_N;
case 18: return NKCODE_O;
case 19: return NKCODE_P;
case 20: return NKCODE_Q;
case 21: return NKCODE_R;
case 22: return NKCODE_S;
case 23: return NKCODE_T;
case 24: return NKCODE_U;
case 25: return NKCODE_V;
case 26: return NKCODE_W;
case 27: return NKCODE_X;
case 28: return NKCODE_Y;
case 29: return NKCODE_Z;
case 30: return NKCODE_1;
case 31: return NKCODE_2;
case 32: return NKCODE_3;
case 33: return NKCODE_4;
case 34: return NKCODE_5;
case 35: return NKCODE_6;
case 36: return NKCODE_7;
case 37: return NKCODE_8;
case 38: return NKCODE_9;
case 39: return NKCODE_0;
case 40: return NKCODE_ENTER;
case 43: return NKCODE_TAB;
case 44: return NKCODE_SPACE;
case 45: return NKCODE_MINUS;
case 46: return NKCODE_EQUALS;
case 47: return NKCODE_LEFT_BRACKET;
case 48: return NKCODE_RIGHT_BRACKET;
case 49: return NKCODE_BACKSLASH;
case 51: return NKCODE_SEMICOLON;
case 52: return NKCODE_APOSTROPHE;
case 53: return NKCODE_ESCAPE;//NKCODE_GRAVE;
case 54: return NKCODE_COMMA;
case 55: return NKCODE_PERIOD;
case 56: return NKCODE_SLASH;
case 57: return NKCODE_CAPS_LOCK;
case 79: return NKCODE_DPAD_RIGHT;
case 80: return NKCODE_DPAD_LEFT;
case 81: return NKCODE_DPAD_DOWN;
case 82: return NKCODE_DPAD_UP;
case 224: return NKCODE_CTRL_LEFT;
case 225: return NKCODE_SHIFT_LEFT;
case 226: return NKCODE_META_LEFT;
case 227: return NKCODE_ALT_LEFT;
case 229: return NKCODE_SHIFT_RIGHT;
case 230: return NKCODE_META_RIGHT;
case 231: return NKCODE_ALT_RIGHT;
default: return 0;
}
}
View
@@ -0,0 +1,14 @@
//
// SmartKeyboardMap.hpp
// PPSSPP
//
// Created by xieyi on 2017/9/4.
//
//
#ifndef SmartKeyboardMap_hpp
#define SmartKeyboardMap_hpp
int getSmartKeyboardMap(int keycode);
#endif /* SmartKeyboardMap_hpp */
View
@@ -74,7 +74,7 @@ @interface ViewController ()
@property (nonatomic) NSString* bundlePath;
@property (nonatomic) NSMutableArray* touches;
@property (nonatomic) AudioEngine* audioEngine;
@property (nonatomic) iCadeReaderView* iCadeView;
//@property (nonatomic) iCadeReaderView* iCadeView;
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
@property (nonatomic) GCController *gameController __attribute__((weak_import));
#endif
@@ -195,10 +195,10 @@ - (void)viewDidLoad {
dp_xscale = (float)dp_xres / (float)pixel_xres;
dp_yscale = (float)dp_yres / (float)pixel_yres;
self.iCadeView = [[iCadeReaderView alloc] init];
/*self.iCadeView = [[iCadeReaderView alloc] init];
[self.view addSubview:self.iCadeView];
self.iCadeView.delegate = self;
self.iCadeView.active = YES;
self.iCadeView.active = YES;*/
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
if ([GCController class]) {
@@ -85,12 +85,12 @@ - (void)setDelegate:(id<iCadeEventDelegate>)delegate {
_delegate = delegate;
if (!_delegate) return;
_delegateFlags.stateChanged = [_delegate respondsToSelector:@selector(stateChanged:)];
/*_delegateFlags.stateChanged = [_delegate respondsToSelector:@selector(stateChanged:)];
_delegateFlags.buttonDown = [_delegate respondsToSelector:@selector(buttonDown:)];
_delegateFlags.buttonUp = [_delegate respondsToSelector:@selector(buttonUp:)];
_delegateFlags.buttonUp = [_delegate respondsToSelector:@selector(buttonUp:)];*/
}
#pragma mark -
/*#pragma mark -
#pragma mark UIKeyInput Protocol Methods
- (BOOL)hasText {
@@ -136,6 +136,6 @@ - (void)insertText:(NSString *)text {
- (void)deleteBackward {
// This space intentionally left blank to complete protocol
}
}*/
@end
View
@@ -8,7 +8,7 @@
#import <AudioToolbox/AudioToolbox.h>
#import "AppDelegate.h"
#import <AudioToolbox/AudioToolbox.h>
#import "PPSSPPUIApplication.h"
#include "base/NativeApp.h"
@@ -113,6 +113,7 @@ int main(int argc, char *argv[])
// Simulates a debugger. Makes it possible to use JIT (though only W^X)
syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0);
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
return UIApplicationMain(argc, argv, NSStringFromClass([PPSSPPUIApplication class]), nil);
//return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

0 comments on commit f0ba66f

Please sign in to comment.