Keyboard shortcuts?

I looked into SDL_TextInputEvent, it doesn’t fit with the way the frame loop works. I’d have to do some major kludging to make it work. Keyboards are a mess. A few weeks ago on Twitter, John Blow was ranting about how fucked up it was. Oh well…

The numpad works now, but I have to say, it’s a little confusing due to how the phone and keyboard keypads are flipped. I’m not sure I’m going to leave it in.

1 Like

Do you see the buttons being pushed at the same time you push on the keyboard? I can imagine, why this might be confusing but I´m not sure if I will be looking at the screen at the same time I enter the numbers on the keyboard, I can´t be certain until I´ve tried it.

1 Like

Hm… SDL_Event.key.keysym.sym doesn’t work? See the “Code examples” in: http://wiki.libsdl.org/SDL_Keycode
and:
https://wiki.libsdl.org/CategoryKeyboard

Is this the reasons you cannot use all kind of keys in the settings file?
What about allowing (additionally) using scancodes in the settings file, e.g. when 0x prefix is used or when it’s more than 1 character assume scancode.

That’s fine! I can’t stand the phone layout anyway because of this flipping around.

Oh, and will there be a rotary dial DLC later with VR controller support?

:smile: how can a person with your nickname dislike flipped things?

3 Likes

You can do this.

keySelect1 = 249
or
keySelect1 = “1”

None of these do what I need. I can’t be converting to strings and then doing string comparisons just to check keys. That is frame rate-killing.

What I need is: If you press “2” you get “2”, if you press “shift-2” you get “@” (on US keyboards, or what ever is above the 2 on other keyboards).

Or “a” returns “a” and “shift-a” returns “A”.

I’m surprised SDL doesn’t have a function or event for this. It’s so obvious, it makes me wonder if I’m just missing it.

That surprises me too. I haven’t worked with SDL for a while, but I will dig into this when I have some spare time. It works in other games and I am pretty sure I got that working the last time I did stuff with SDL…

[quote=“RonGilbert, post:1, topic:718”]
Since we’re doing a update in the next few weeks/month, are there any UI/keyboard/mouse changes you’d like to see?
[/quote]There is one thing Day of the Tentacle handles slightly more comfortable:
If you left click on an item in the inventory, “use” is selected automatically. If you right click, you “look at” it. That way, both mouse buttons have useful default verbs in the inventory.

And some cosmetic detail in Day of the Tentacle and most later LucasArts adventures: When use is selected on an item which needs to be combined, the mouse cursor turns into the item’s icon.

Both were nice tweaks, imho.

…which was mentioned on the blog back then: Options.
How embarrassing I forgot that :slight_smile:

That seems a work for SDL_TextInputEvent, that handles all the mapping and gives you the UTF-8 chars. But it seems that you already had a look at it. What’s the issue?

I speak for myself: I’m used to. So, for me it’s fine that way.

Haha, the arrangement in that picture makes it look like you´re still accessing the internet “the old fashioned way”.:slight_smile:

1 Like

For the extra nerdiness, make Thimbleweed Park identify itself as an SIP device, so you can call in with a real phone.

With SDL_TextInputEvent you get only one key (after another). This works for me under Ubuntu with a english and a german layout:

SDL_Event e;
while( SDL_PollEvent( &e ) != 0 )
{
   //...
   if (e.type==SDL_TEXTINPUT)
   {
      switch(e.text.text[0])
      {
         case 'z':
         printf("z\n");
         break;
         case 'Z':
         printf("Z\n");
      }
   }
  
   else if( e.type == SDL_KEYDOWN )
   {
       // handle other keypresses ...
   }
}

e.text.text is a char[32] with one Unicode character.

An alternative is to check if z and shift are pressed together:

SDL_Event e;
while( SDL_PollEvent( &e ) != 0 )
{
   //...
   if( e.type == SDL_KEYDOWN )
   {
      switch( e.key.keysym.sym )
      {
         case SDLK_z:
         printf( "z\n" );
         if(SDL_GetModState()==KMOD_LSHIFT) printf("Z (and Shift)\n");
         break;
      }
}

With the latter method you have to handle @ and other special keys yourself. But it produces the letter Z on a QWERTZ and a QWERTY keyboard.

If both won’t work, you have to use a Unicode library, I have to fear. Another solution would be to allow the players to change the keyboard mapping in the game options with some mouse clicks. But that would be additional work of course…

/edit: “e.key.keysym.sym” is a value that you can compare with the SDL_Keycode constants (https://wiki.libsdl.org/SDL_Keycode). The conversion to a string in the example on this site: https://wiki.libsdl.org/SDL_Keycode is done only to print the character on the screen. The value in “e.key.keysym.sym” is (in most cases/on most systems) the Unicode value of the corresponding key. So you can even do:
if(e.key.keysym.sym == 0x31) // then the key with the number 1 is pressed (1 in Unicode is hex 0x31 or decimal 49)
e.text.text saves a Unicode value too. So you don’t have to compare or convert a string.

I looked at SDL_TEXTINPUT at the beginning of he project and it didn’t work they way I needed, I’ll go back and look at it again.

If it still doesn’t work for you, just let me know (if possible with a short description of the problems). I will try to find another way or a workaround.

As far as I understand it, SDL_TEXTINPUT events are really meant for typing stuff into a textfield or such, and need to be specifically enabled with SDL_StartTextInput. Can’t image that this is what you’ll want.

key.keysym.sym will give the unmodified key based on the users keyboard layout, but if you’re actually interested in knowing when something like “@” or other special symbols were typed, this won’t help you much. The data for the SDL_TEXTINPUT event is directly retrieved from the OS-specifc input events, so there’s no a way to derive that from pure SDL keypress events.

Uppercase/lowercase letters should be fine, though, by taking the modifier key state into account. Still a bit tricky, when capslock comes into play.

I guess if this wouldn’t be time critical, you could drop a few lines over at https://discourse.libsdl.org/. Ryan and Sam are helpful enough and perhaps a solution could be worked out. Though I assume it will be a matter of months, or longer, if code changes are involved.

This was my experience when I first tried to around a year ago. I might pop over to the SDL forums. My guess is there is no way to do this, otherwise it would be documented.

No, you can use SDL_TEXTINPUT events without SDL_StartTextInput. The latter one is only needed to turn explicitly on and of the SDL_TEXTINPUT event (for example if you want to offer a text input field or an editor). My code posted above works.

SDL_TEXTINPUT is meant to allow the input of Unicode characters. Textfields are just one example.
See the description of SDL_TextInputEvent: https://wiki.libsdl.org/SDL_TextInputEvent
And the “Tutorial” example: https://wiki.libsdl.org/Tutorials/TextInput

The SDL_TEXTINPUT and the SDL_KEYDOWN events are even polled together so you can mix them like in my example above.

Regarding the forum: You may want to read this thread before opening a new one :slight_smile: SDL2 and unicode characters from key events - #18 by Jared_Maddox - SDL Development - Simple Directmedia Layer

Cite (SDL2 and unicode characters from key events - #18 by Jared_Maddox - SDL Development - Simple Directmedia Layer):

There are three options:

  1. You just want to know when particular keys are pressed.
    Answer) Use scancodes, and allow the user to remap keys whenever they want.
  1. You want Unicode.
    Answer) Use the text-editing events, because that’s the only way that
    you can get all Unicode characters.
  1. You want to know when keys that map directly to Unicode are pressed.
    Answer) Use keycodes, checking the high bit to determine if it carries
    a Unicode value or a scancode value.

/edit: clarified my second sentence about SDL_StartTextInput() (see https://wiki.libsdl.org/SDL_StartTextInput)

1 Like