Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Keyboard on iOS

This thread is locked; no one can reply to it. rss feed Print
Keyboard on iOS
seibelj
Member #16,618
January 2017

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
Member #11,410
October 2009

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
Member #1,146
March 2001
avatar

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?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Elias
Member #358
May 2000

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...)

--
"Either help out or stop whining" - Evert

jmasterx
Member #11,410
October 2009

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

Mark Oates
Member #1,146
March 2001
avatar

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?

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Elias
Member #358
May 2000

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.

--
"Either help out or stop whining" - Evert

seibelj
Member #16,618
January 2017

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.

Go to: