Keyboard on iOS
seibelj

I have been trying for many hours to programmatically show and hide the keyboard on iOS.

The file containing my main method is in C, not objective c. How can I get the keyboard to show and hide?

Is the answer something like in this stack overflow question? http://stackoverflow.com/questions/7253477/how-to-display-the-iphone-ipad-keyboard-over-a-full-screen-opengl-es-app

Do I need to change the file containing my main method to a .m (objective c) file? Can I leave it as .c, then call out to a .m file (somehow)?

The more specific you can be, the better. The documentation for iOS with allegro is pretty sparse.

Thanks.

jmasterx

I made a working implementation in my game:
https://github.com/jmasterx/StemwaterSpades/tree/master/Spades%20Game/Game/platform

This also handles in app purchases.

The solution is heavily coupled to my gui and game but should be adaptable to another game.

My solution actually allows you to write directly to my text widgets when you tap a textbox.

Mark Oates

That's impressive, jmasterx. I would love to have both features (in-app purchases, native touch keyboard) in AllegroFlare.

Is it just for iOS, or does it also handle Android?

Elias

In android it's very simple anyway as your game provides the Activity.java and you can just copy and paste some sample Java code. (Doing it in the NDK would be an alternative but more involved...)

jmasterx

Never finished the Android port. Got it running n there but lost interest. Never did the keyboard code.

Mark Oates
Elias said:

In android it's very simple anyway as your game provides the Activity.java and you can just copy and paste some sample Java code. (Doing it in the NDK would be an alternative but more involved...)

Could this be incorporated through C++ code?

Elias

Yes, in Android NDK=C++ API and SDK=Java API :) But Allegro was written in mostly the SDK for some reason and most actual Android sample code is SDK, so it's easier dealing with that.

seibelj

Thank you so much jmasterx. I was struggling with that for several hours. My Objective-C experience is pretty minimal.

For anyone who is curious about how to do this in the future using C, here's what I had to do:

  • Created a new main file for iOS that is a clone of my old main.c file renamed to main.m (objective-c). I have come to the conclusion that all of my supported platforms will get their own main file, which will do the bare minimum to bootstrap the program and set various environment values, then start the main game loop.

  • My main.m file imports <Foundation/Foundation.h> and <allegro5/allegro_iphone.h> in addition to all the other stuff.

  • Make main.m a bare minimum implementation by putting this after my imports:

    @interface main_ios : NSObject
    
    @end
    @implementation main_ios
    
    @end
  • Created new KeyboardHandleriOS.m implementation and KeyboardHandleriOS.h header files. The contents of these files is basically what jmasterx has, with all the C++ stuff translated to C and modified from his code base to mine.

  • KeyboardHandleriOS *kHandler; defined above my main method.

  • After the display is initialized successfully, only then do you initialize the keyboard class, with kHandler = [[KeyboardHandleriOS alloc] init];

Edit - About Android, implementing that was trivial from wiki instructions: https://wiki.allegro.cc/index.php?title=Running_Allegro_applications_on_Android#Displaying_the_Android_keyboard

Edit 2 - It doesn't seem that the keyboard eventing system gets key strokes as they happen. As my current system is listening for these events, my plan is to emit them directly into the eventing system from the KeyboardHandleriOS code, so that everything expecting keyboard events gets them as they happen, unless anyone has any better ideas.

Thread #616672. Printed from Allegro.cc