The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[2.0.4+] - Get "char" From Keyboard Input?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
[2.0.4+] - Get "char" From Keyboard Input?

Hi,

After a long stint with HTML5 and then GameMaker:Studio,
our development team has come back to cross-platform C++ with SDL2.

We are in the process of improving our current SDL2 2-D game engine but need some help:
How can we get the "char" pressed on the keyboard?

We looked here but did not see anything to use:
https://wiki.libsdl.org/CategoryKeyboard

Thank you in advance!
actsl


Joined: 09 Feb 2016
Posts: 83
What do you need, key code, scan code, or text from keyboard?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
actsl wrote:
What do you need, key code, scan code, or text from keyboard?
Hi,

We need the "char" character the user pressed on the keyboard.
Need it for new high score name input.

Thanks!
actsl


Joined: 09 Feb 2016
Posts: 83
JeZ-l-Lee wrote:
Need it for new high score name input.

Name input, i see, this is a text from keyboard.

You cannot get char from the keyboard. All keyboard input is UTF-8 (8-bit Unicode). If event->type is SDL_TEXTINPUT , then event->text.text contains the string that is the UTF-8 code of the character that corresponds to the pressed key, 1 to 4 chars. If you only use ACII, then the length of that string is always 1 char. It is important to call SDL_StartTextInput() before starting text input.

You may see from the code of my widget toolkit below, how it is done. Also the processing that you likely need, if some characters are not ASCII.
[2.0.4+] - Get "char" From Keyboard Input?
Jim Clark
Guest

Hello,
are you referring to something like this? 

https://wiki.libsdl.org/SDLKeycodeLookup

each keycode has a specific hex value that is a char if im not mistaken.

On Tue, May 10, 2016 at 7:58 PM, JeZ-l-Lee wrote:
Quote:



actsl wrote:

What do you need, key code, scan code, or text from keyboard?


Hi,

We need the "char" character the user pressed on the keyboard.
Need it for new high score name input.

Thanks!



JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

[2.0.4+] - Get "char" From Keyboard Input?
Daniel Gibson
Guest

Keycodes don't work well as chars, especially for non-ascii chars (one
thing is that IIRC they're not unicode chars, the other is that one
might use dead keys and input "`e" for "é" and here keycodes won't give
you at all what you want.

Just use SDL_TEXTINPUT events, that's what they're for.

Cheers,
Daniel

On 05/11/2016 02:21 AM, Jim Clark wrote:
Quote:
Hello,
are you referring to something like this?

https://wiki.libsdl.org/SDLKeycodeLookup

each keycode has a specific hex value that is a char if im not mistaken.

On Tue, May 10, 2016 at 7:58 PM, JeZ-l-Lee

<mailto:> wrote:

__



actsl wrote:

What do you need, key code, scan code, or text from keyboard?

Hi,

We need the "char" character the user pressed on the keyboard.
Need it for new high score name input.

Thanks!


------------------------------------------------------------------------

JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com <http://www.16BitSoft.com>

_______________________________________________
SDL mailing list
<mailto:
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
actsl


Joined: 09 Feb 2016
Posts: 83
I were referring to text input.
[2.0.4+] - Get "char" From Keyboard Input?
Jim Clark
Guest

thank you for the warning! 

On Tue, May 10, 2016 at 8:35 PM, Daniel Gibson wrote:
Quote:
Keycodes don't work well as chars, especially for non-ascii chars (one thing is that IIRC they're not unicode chars, the other is that one might use dead keys and input "`e" for "é" and here keycodes won't give you at all what you want.

Just use SDL_TEXTINPUT events, that's what they're for.

Cheers,
Daniel

On 05/11/2016 02:21 AM, Jim Clark wrote:
Quote:
Hello,
are you referring to something like this?

https://wiki.libsdl.org/SDLKeycodeLookup

each keycode has a specific hex value that is a char if im not mistaken.

On Tue, May 10, 2016 at 7:58 PM, JeZ-l-Lee

<mailto:> wrote:

    __



    actsl wrote:       

    What do you need, key code, scan code, or text from keyboard?       

    Hi,

    We need the "char" character the user pressed on the keyboard.
    Need it for new high score name input.

    Thanks!


    ------------------------------------------------------------------------

    JeZxLee
    JessePalser <AT> GMail <DOT> com
    16BitSoft Inc.
    Video Game Design Studio
    www.16BitSoft.com <http://www.16BitSoft.com>

    _______________________________________________
    SDL mailing list
    <mailto:
    http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org