Skip to content
This repository
Browse code

Merge pull request #3282 from Memphiz/iosbtkeys

[ios] - add support for bluetooth keyboard
  • Loading branch information...
commit 697e8b6f932fbbc2c592e5755928fcfbebc5d4f0 2 parents a271ec9 + b4e410c
Memphiz authored September 30, 2013
65  xbmc/osx/ios/XBMCApplication.m
@@ -152,6 +152,69 @@ - (void)dealloc
152 152
 }
153 153
 @end
154 154
 
  155
+@interface XBMCApplication : UIApplication{
  156
+}
  157
+@end
  158
+
  159
+@implementation XBMCApplication
  160
+#define GSEVENT_TYPE 2
  161
+#define GSEVENT_FLAGS 12
  162
+#define GSEVENTKEY_KEYCODE 15
  163
+#define GSEVENT_TYPE_KEYUP 11
  164
+
  165
+- (void)sendEvent:(UIEvent *)event
  166
+{ 
  167
+  [super sendEvent:event];
  168
+
  169
+  if ([event respondsToSelector:@selector(_gsEvent)]) 
  170
+  {
  171
+    // Key events come in form of UIInternalEvents.
  172
+    // They contain a GSEvent object which contains 
  173
+    // a GSEventRecord among other things
  174
+    int *eventMem;
  175
+    eventMem = (int *)[event performSelector:@selector(_gsEvent)];
  176
+    if (eventMem) 
  177
+    {
  178
+      // So far we got a GSEvent :)
  179
+      int eventType = eventMem[GSEVENT_TYPE];
  180
+      if (eventType == GSEVENT_TYPE_KEYUP) 
  181
+      {
  182
+        // Now we got a GSEventKey!
  183
+        
  184
+        // Read flags from GSEvent
  185
+        // for modifier keys if we want to use them somehow at a later time
  186
+        //int eventFlags = eventMem[GSEVENT_FLAGS];
  187
+        // Read keycode from GSEventKey
  188
+        UniChar tmp = (UniChar)eventMem[GSEVENTKEY_KEYCODE];
  189
+        XBMCKey key = XBMCK_UNKNOWN;
  190
+        switch (tmp)
  191
+        {
  192
+          case 0x4f:
  193
+            // right
  194
+            key = XBMCK_RIGHT;
  195
+            break;
  196
+          case 0x50:
  197
+            // left
  198
+            key = XBMCK_LEFT;
  199
+            break;
  200
+          case 0x51:
  201
+            // down
  202
+            key = XBMCK_DOWN;
  203
+            break;
  204
+          case 0x52:
  205
+            // up
  206
+            key = XBMCK_UP;
  207
+            break;
  208
+          default:
  209
+            return; // not supported by us - return...
  210
+        }
  211
+        [g_xbmcController sendKey:key];
  212
+      }
  213
+    }
  214
+  }
  215
+}
  216
+@end
  217
+
155 218
 int main(int argc, char *argv[]) {
156 219
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];	
157 220
   int retVal = 0;
@@ -167,7 +230,7 @@ int main(int argc, char *argv[]) {
167 230
   
168 231
   @try
169 232
   {
170  
-    retVal = UIApplicationMain(argc,argv,@"UIApplication",@"XBMCApplicationDelegate");
  233
+    retVal = UIApplicationMain(argc,argv,@"XBMCApplication",@"XBMCApplicationDelegate");
171 234
     //UIApplicationMain(argc, argv, nil, nil);
172 235
   } 
173 236
   @catch (id theException) 
2  xbmc/osx/ios/XBMCController.h
@@ -35,7 +35,7 @@ typedef enum
35 35
   IOS_PLAYBACK_PLAYING
36 36
 } IOSPlaybackState;
37 37
 
38  
-@interface XBMCController : UIViewController <UIGestureRecognizerDelegate>
  38
+@interface XBMCController : UIViewController <UIGestureRecognizerDelegate, UIKeyInput>
39 39
 {
40 40
   UIWindow *m_window;
41 41
   IOSEAGLView  *m_glView;
60  xbmc/osx/ios/XBMCController.mm
@@ -252,6 +252,50 @@ @implementation XBMCController
252 252
 @synthesize m_networkAutoSuspendTimer;
253 253
 @synthesize nowPlayingInfo;
254 254
 //--------------------------------------------------------------
  255
+- (void) sendKeypressEvent: (XBMC_Event) event
  256
+{
  257
+  event.type = XBMC_KEYDOWN;
  258
+  CWinEventsIOS::MessagePush(&event);
  259
+
  260
+  event.type = XBMC_KEYUP;
  261
+  CWinEventsIOS::MessagePush(&event);
  262
+}
  263
+
  264
+// START OF UIKeyInput protocol
  265
+- (BOOL)hasText
  266
+{
  267
+  return NO;
  268
+}
  269
+
  270
+- (void)insertText:(NSString *)text
  271
+{
  272
+  XBMC_Event newEvent;
  273
+  memset(&newEvent, 0, sizeof(newEvent));
  274
+  unichar currentKey = [text characterAtIndex:0];
  275
+
  276
+  // handle upper case letters
  277
+  if (currentKey >= 'A' && currentKey <= 'Z')
  278
+  {
  279
+    newEvent.key.keysym.mod = XBMCKMOD_LSHIFT;
  280
+    currentKey += 0x20;// convert to lower case
  281
+  }
  282
+
  283
+  // handle return
  284
+  if (currentKey == '\n' || currentKey == '\r')
  285
+    currentKey = XBMCK_RETURN;
  286
+
  287
+  newEvent.key.keysym.sym = (XBMCKey)currentKey;
  288
+  newEvent.key.keysym.unicode = currentKey;
  289
+
  290
+  [self sendKeypressEvent:newEvent];
  291
+}
  292
+
  293
+- (void)deleteBackward
  294
+{
  295
+  [self sendKey:XBMCK_BACKSPACE];
  296
+}
  297
+// END OF UIKeyInput protocol
  298
+
255 299
 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
256 300
 {  
257 301
   //on external screens somehow the logic is rotated by 90°
@@ -312,12 +356,8 @@ -(void)sendKey:(XBMCKey) key
312 356
   
313 357
   //newEvent.key.keysym.unicode = key;
314 358
   newEvent.key.keysym.sym = key;
  359
+  [self sendKeypressEvent:newEvent];
315 360
   
316  
-  newEvent.type = XBMC_KEYDOWN;
317  
-  CWinEventsIOS::MessagePush(&newEvent);
318  
-  
319  
-  newEvent.type = XBMC_KEYUP;
320  
-  CWinEventsIOS::MessagePush(&newEvent);
321 361
 }
322 362
 //--------------------------------------------------------------
323 363
 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
@@ -787,6 +827,16 @@ - (void)viewWillDisappear:(BOOL)animated
787 827
   [super viewWillDisappear:animated];
788 828
 }
789 829
 //--------------------------------------------------------------
  830
+-(UIView *)inputView
  831
+{
  832
+  // override our input view to an empty view
  833
+  // this prevents the on screen keyboard
  834
+  // which would be shown whenever this UIResponder
  835
+  // becomes the first responder (which is always the case!)
  836
+  // caused by implementing the UIKeyInput protocol
  837
+  return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
  838
+}
  839
+//--------------------------------------------------------------
790 840
 - (BOOL) canBecomeFirstResponder
791 841
 {
792 842
   return YES;

0 notes on commit 697e8b6

Please sign in to comment.
Something went wrong with that request. Please try again.