libsdl-org / sdlwiki

This is the raw contents of SDL's wiki. You can edit this through GitHub or at https://wiki.libsdl.org/ now!
https://wiki.libsdl.org/
79 stars 32 forks source link

SDL_TextInputEvent requires SDL_StartTextInput to work #537

Closed Semphriss closed 3 months ago

Semphriss commented 3 months ago

While developing an app, I tried catching text input events and saw none were emitted when I pressed keys on my keyboards. I didn't know why, until I remembered a discussion on the SDL repo about disabling text input events by default, until SDL_StartTextInput() is called. This wasn't documented at https://wiki.libsdl.org/SDL3/SDL_TextInputEvent, which I looked first to see if I was missing anything about that structure.

Would it be good to add a note on that page that SDL_StartTextInput() (and related functions) need to be used for that event to work?

icculus commented 3 months ago

Okay, @slouken, just so I document this correctly: in SDL3, on desktop, this defaults to enabled if it thinks there's a physical keyboard attached, and false otherwise (so as not to pop up a virtual keyboard over the game if one isn't immediately needed), right? And always defaults to off on iOS/Android, physical keyboard or not?

(And SDL2 was "always enabled by default on desktop, and disabled by default on mobile," since Steam Deck type things hadn't arrived yet.)

Semphriss commented 3 months ago

[...] in SDL3, on desktop, this defaults to enabled if it thinks there's a physical keyboard attached, and false otherwise [...]

It seems to be disabled by default on my desktop device (stock Ubuntu 22.04, Wayland, a physical keyboard, mouse and screens, no touchscreens, no drawing tablet, no other funny device) with latest SDL3 (https://github.com/libsdl-org/SDL/commit/4d32f66fe7a1946384b062cea87f520b75139536). Should I open an issue about it on the SDL repo?

icculus commented 3 months ago

Let Sam answer when he gets a moment, I could be wrong about the final decisions on this.

slouken commented 3 months ago

For SDL2 it defaults on for desktop and off for mobile. For SDL3 it defaults off everywhere. Please feel free to submit a PR to improve the documentation in a way that makes sense for you.

Thanks!

icculus commented 3 months ago

See? I'm glad I asked. :)

I've fixed up the wiki now.