iPad keyboard with SDL2?

Is there any way to control and interact with the keyboard GUI on the iPad/iPhone with SDL2? It would be cool if there was a function to show and hide it, and when text is entered for some sort of SDL_KeyboardEvent to be triggered. But I couldn’t find any current way to do this via SDL2.

I suppose I could implement my own keyboard GUI, but that seems like reinventing the wheel.
I suppose I could use some non-SDL code to show/hide the keyboard, but it would be cool if these were more closely integrated with SDL somehow so all iPad/iPhone developers had a standardized way to implement keyboard functionality.

Oh, I was doing a search for iPad and iOS.

Thanks.

I just updated via hg clone http://hg.libsdl.org/SDL.
I open up the SDL2 folder and open Xcode-iOS/Demos/Demos.xcodeproj.
I select the Keyboard (iPad Simulator) target, but apparently keyboard.c has some outdated terms, so I make the following changes:

keyboard.c:38 Rename SDL_ScanCode to SDL_Scancode
keyboard.c:40 Rename SDLMod to Uint16
keyboard.c:117 Rename SDL_KeySym to SDL_Keysym
keyboard.c:243 Rename SDLMod to Uint16
keyboard.c:243 Rename SDL_ScanCode to SDL_Scancode

Everything compiles and the demo runs fine.

I want to use some C++ stuff in keyboard.c, so I rename it to keyboard.cpp.

I then need to make 4 small changes:
keyboard.cpp:28 Change “0” to "SDL_FALSE"
keyboard.cpp:277 Change “0” to "SDL_FALSE"
keyboard.cpp:285 Change “0” to "SDL_FALSE"
keyboard.cpp:291 Cast as a SDL_bool with “lastCharWasColon = (SDL_bool)”

And then I come to the problem I can’t figure out.
Unless I comment out keyboard.cpp:304 to omit the call to “SDL_iPhoneKeyboardToggle(window);”, when I try to compile, I get the following link error:

Code:
Undefined symbols for architecture i386:
“SDL_iPhoneKeyboardToggle(SDL_Window*)”, referenced from:
_SDL_main in keyboard.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It seems like a conflict of including C++ and .m files. I’m not sure what is the best way to resolve this. I suppose I could rename all of the .m files to .mm files, but I don’t think that is the best way to handle this (and I’m not even sure if that would fix the issue). My guess is there is some option in the Xcode project that I need to use, but I have so far not been able to figure out what.

Anyone know what I need to change to fix that linking error?

It looks like the keyboard header doesn’t have C++ ifdefs, and I’ll fix
that now.>From README.iOS:

==============================================================================
Notes – Keyboard

SDL for iPhone contains several additional functions related to keyboard
visibility. These functions are not part of the SDL standard API, but are
necessary for revealing and hiding the iPhone’s virtual onscreen keyboard.
You can use them in your own applications by including a copy of the
SDL_uikitkeyboard.h header (located in src/video/uikit) in your project.

int SDL_iPhoneKeyboardShow(SDL_Window * window)
– reveals the onscreen keyboard. Returns 0 on success and -1 on error.
int SDL_iPhoneKeyboardHide(SDL_Window * window) – hides the onscreen
keyboard. Returns 0 on success and -1 on error.
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window)
– returns whether or not the onscreen keyboard is currently visible.
int SDL_iPhoneKeyboardToggle(SDL_Window * window)
– toggles the visibility of the onscreen keyboard. Returns 0 on
success and -1 on
error.

On Fri, May 25, 2012 at 6:17 AM, Trev wrote:

**
I just updated via hg clone http://hg.libsdl.org/SDL.
I open up the SDL2 folder and open Xcode-iOS/Demos/Demos.xcodeproj.
I select the Keyboard (iPad Simulator) target, but apparently keyboard.c
has some outdated terms, so I make the following changes:

keyboard.c:38 Rename SDL_ScanCode to SDL_Scancode
keyboard.c:40 Rename SDLMod to Uint16
keyboard.c:117 Rename SDL_KeySym to SDL_Keysym
keyboard.c:243 Rename SDLMod to Uint16
keyboard.c:243 Rename SDL_ScanCode to SDL_Scancode

Everything compiles and the demo runs fine.

I want to use some C++ stuff in keyboard.c, so I rename it to keyboard.cpp.

I then need to make 4 small changes:
keyboard.cpp:28 Change “0” to "SDL_FALSE"
keyboard.cpp:277 Change “0” to "SDL_FALSE"
keyboard.cpp:285 Change “0” to "SDL_FALSE"
keyboard.cpp:291 Cast as a SDL_bool with “lastCharWasColon = (SDL_bool)”

And then I come to the problem I can’t figure out.
Unless I comment out keyboard.cpp:304 to omit the call to
"SDL_iPhoneKeyboardToggle(window);", when I try to compile, I get the
following link error:

Code:

Undefined symbols for architecture i386:
“SDL_iPhoneKeyboardToggle(SDL_Window*)”, referenced from:
_SDL_main in keyboard.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see
invocation)

It seems like a conflict of including C++ and .m files. I’m not sure what
is the best way to resolve this. I suppose I could rename all of the .m
files to .mm files, but I don’t think that is the best way to handle this
(and I’m not even sure if that would fix the issue). My guess is there is
some option in the Xcode project that I need to use, but I have so far not
been able to figure out what.

Anyone know what I need to change to fix that linking error?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sam Lantinga wrote:

It looks like the keyboard header doesn’t have C++ ifdefs, and I’ll fix that now.

Thanks, Sam.
I’m not sure if you fixed this yet, but I don’t see the fix reflected in http://hg.libsdl.org/SDL/file/263e2c049c22/src/video/uikit/SDL_uikitkeyboard.h

If it is online, where should I go to get the fix?

Here you go:
http://hg.libsdl.org/SDL/rev/53a0e9f5db8dOn Fri, May 25, 2012 at 5:59 PM, Trev wrote:

**

Sam Lantinga wrote:

It looks like the keyboard header doesn’t have C++ ifdefs, and I’ll fix
that now.

Thanks, Sam.
I’m not sure if you fixed this yet, but I don’t see the fix reflected in
http://hg.libsdl.org/SDL/file/263e2c049c22/src/video/uikit/SDL_uikitkeyboard.h

If it is online, where should I go to get the fix?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sam Lantinga wrote:

Here you go:http://hg.libsdl.org/SDL/rev/53a0e9f5db8d (http://hg.libsdl.org/SDL/rev/53a0e9f5db8d)

I just updated. I notice that keyboard.c is now up to date and the project builds with no errors right off the bat.
But when I try to rename keyboard.c to keyboard.cpp, I start to encounter some problems.

I then need to make the following changes (possibly just due to my compiler being picky):
keyboard.cpp:28, Renamed 0 to SDL_FALSE
keyboard.cpp:54-102, explicitly cast KMOD_SHIFT as (SDL_Keymod)KMOD_SHIFT
keyboard.cpp:273, cast event.key.keysym.mod as a SDL_Keymod
keyboard.cpp:277, Renamed 0 to SDL_FALSE
keyboard.cpp:285, Renamed 0 to SDL_FALSE
keyboard.cpp:291, Explicitly cast as SDL_bool

And then I come to the same exact problem I had before:

Code:
Undefined symbols for architecture i386:
“SDL_iPhoneKeyboardToggle(SDL_Window*)”, referenced from:
_SDL_main in keyboard.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there some step I’m missing?

I’m still getting the error:
Code:
Undefined symbols for architecture i386:
“SDL_iPhoneKeyboardToggle(SDL_Window*)”, referenced from:
_SDL_main in keyboard.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there some other step I need to get this to work with c++? Do I need to define a preprocessor macro or something?

Has anyone got SDL_iPhoneKeyboardToggle working with a C++ file? If anyone could confirm that it does or does not work with C++, that would help me investigate.

That function might not be declared extern “C” perhaps?On 06/13/2012 04:38 AM, Trev wrote:

I’m still getting the error:

Code:

Undefined symbols for architecture i386:
“SDL_iPhoneKeyboardToggle(SDL_Window*)”, referenced from:
_SDL_main in keyboard.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there some other step I need to get this to work with c++? Do I need to define a preprocessor macro or something?

Has anyone got SDL_iPhoneKeyboardToggle working with a C++ file? If anyone could confirm that it does or does not work with C++, that would help me investigate.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

Forest Hale wrote:

That function might not be declared extern “C” perhaps?
So what could be done to fix that? Sam already altered SDL_uikitkeyboard.h with the aim of making it able to be used in C or C++, but whatever he did seems not to have fixed the error.
Anyone can take a look if you want. Get the latest SDL with HG, and try converting the demo keyboard.c to keyboard.cpp. You should encounter the exact same error as I am.