# Keyboard shortcuts?

**URL:** <https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718>\
**Category:** Development/Design\
**Created:** [June 7, 2017, 2:33pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718 "2017-06-07T14:33:40Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![RonGilbert](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/rongilbert/32/7_2.png) [@RonGilbert](https://forums.thimbleweedpark.com/u/RonGilbert)\
**Post date:** [June 8, 2017, 5:13pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/41 "2017-06-08T17:13:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![milanfahrnholz](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@milanfahrnholz](https://forums.thimbleweedpark.com/u/milanfahrnholz)\
**Post date:** [June 8, 2017, 5:18pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/42 "2017-06-08T17:18:18Z")

</div>

> [@RonGilbert](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Someone](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Someone](https://forums.thimbleweedpark.com/u/Someone)\
**Post date:** [June 8, 2017, 6:23pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/43 "2017-06-08T18:23:16Z")

</div>

> [@RonGilbert](#):
>
> Keyboards are a mess.

Hm… SDL\_Event.key.keysym.sym doesn’t work? See the “Code examples” in: [http://wiki.libsdl.org/SDL\_Keycode](http://wiki.libsdl.org/SDL_Keycode)  
and:  
[https://wiki.libsdl.org/CategoryKeyboard](https://wiki.libsdl.org/CategoryKeyboard)

---

<div class="post-metadata">

**Author:** ![Nor\_Treblig](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/nor_treblig/32/216_2.png) [@Nor\_Treblig](https://forums.thimbleweedpark.com/u/Nor_Treblig)\
**Post date:** [June 8, 2017, 7:02pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/44 "2017-06-08T19:02:09Z")

</div>

> [@RonGilbert](#):
>
> FWIW, implementing keyboard input is a PITA. All you get back are scan codes, and they are completely different on different keyboards, so you have to do a lot of odd mapping

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.

> [@RonGilbert](#):
>
> The numpad works now, but I have to say, it’s a little confusing due to how the phone and keyboard keypads are flipped.

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?

---

<div class="post-metadata">

**Author:** ![Ema](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/ema/32/14101_2.png) [@Ema](https://forums.thimbleweedpark.com/u/Ema)\
**Post date:** [June 8, 2017, 8:35pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/45 "2017-06-08T20:35:14Z")

</div>

> [@Nor\_Treblig](#):
>
> That’s fine! I can’t stand the phone layout anyway because of this flipping around.

😄 how can a person with your nickname dislike flipped things?

---

<div class="post-metadata">

**Author:** ![RonGilbert](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/rongilbert/32/7_2.png) [@RonGilbert](https://forums.thimbleweedpark.com/u/RonGilbert)\
**Post date:** [June 8, 2017, 8:36pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/46 "2017-06-08T20:36:00Z")

</div>

> [@Nor\_Treblig](#):
>
> What about allowing (additionally) using scancodes in the settings file

You can do this.

keySelect1 = 249  
or  
keySelect1 = “1”

---

<div class="post-metadata">

**Author:** ![RonGilbert](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/rongilbert/32/7_2.png) [@RonGilbert](https://forums.thimbleweedpark.com/u/RonGilbert)\
**Post date:** [June 8, 2017, 8:41pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/47 "2017-06-08T20:41:18Z")

</div>

> [@Someone](#):
>
> Hm… SDL\_Event.key.keysym.sym doesn’t work? See the “Code examples” in:

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.

---

<div class="post-metadata">

**Author:** ![Someone](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Someone](https://forums.thimbleweedpark.com/u/Someone)\
**Post date:** [June 8, 2017, 9:10pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/48 "2017-06-08T21:10:00Z")

</div>

> [@RonGilbert](#):
>
> 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…

---

<div class="post-metadata">

**Author:** ![LogicDeLuxe](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/logicdeluxe/32/15335_2.png) [@LogicDeLuxe](https://forums.thimbleweedpark.com/u/LogicDeLuxe)\
**Post date:** [June 8, 2017, 9:13pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/49 "2017-06-08T21:13:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nor\_Treblig](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/nor_treblig/32/216_2.png) [@Nor\_Treblig](https://forums.thimbleweedpark.com/u/Nor_Treblig)\
**Post date:** [June 8, 2017, 10:14pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/50 "2017-06-08T22:14:39Z")

</div>

> [@RonGilbert](#):
>
> You can do this.
> 
> keySelect1 = 249  
> or  
> keySelect1 = “1”

…which was mentioned on the blog back then: [Options](https://blog.thimbleweedpark.com/options_options).  
How embarrassing I forgot that 🙂

---

<div class="post-metadata">

**Author:** ![LowLevel](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/lowlevel/32/48_2.png) [@LowLevel](https://forums.thimbleweedpark.com/u/LowLevel)\
**Post date:** [June 8, 2017, 10:25pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/51 "2017-06-08T22:25:38Z")

</div>

> [@RonGilbert](#):
>
> Or “a” returns “a” and “shift-a” returns “A”.

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?

---

<div class="post-metadata">

**Author:** ![ZakPhoenixMcKracken](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/zakphoenixmckracken/32/41_2.png) [@ZakPhoenixMcKracken](https://forums.thimbleweedpark.com/u/ZakPhoenixMcKracken)\
**Post date:** [June 9, 2017, 7:57am UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/52 "2017-06-09T07:57:12Z")

</div>

> [@RonGilbert](#):
>
> 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.

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

 ![](https://canada1.discourse-cdn.com/flex030/uploads/thimbleweedpark/original/1X/f04a33829bbb1a5f937639aabd8d955b48825178.jpg)

---

<div class="post-metadata">

**Author:** ![milanfahrnholz](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@milanfahrnholz](https://forums.thimbleweedpark.com/u/milanfahrnholz)\
**Post date:** [June 9, 2017, 10:40am UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/53 "2017-06-09T10:40:18Z")

</div>

> [@ZakPhoenixMcKracken](#):
>
> 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”.🙂

---

<div class="post-metadata">

**Author:** ![LogicDeLuxe](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/logicdeluxe/32/15335_2.png) [@LogicDeLuxe](https://forums.thimbleweedpark.com/u/LogicDeLuxe)\
**Post date:** [June 9, 2017, 11:04am UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/54 "2017-06-09T11:04:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Someone](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Someone](https://forums.thimbleweedpark.com/u/Someone)\
**Post date:** [June 9, 2017, 11:47am UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/55 "2017-06-09T11:47:31Z")

</div>

> [@RonGilbert](#):
>
> I can’t be converting to strings and then doing string comparisons just to check keys. That is frame rate-killing.

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](https://wiki.libsdl.org/SDL_Keycode)). The conversion to a string in the example on this site: [https://wiki.libsdl.org/SDL\_Keycode](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.

---

<div class="post-metadata">

**Author:** ![RonGilbert](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/rongilbert/32/7_2.png) [@RonGilbert](https://forums.thimbleweedpark.com/u/RonGilbert)\
**Post date:** [June 9, 2017, 3:17pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/56 "2017-06-09T15:17:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Someone](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Someone](https://forums.thimbleweedpark.com/u/Someone)\
**Post date:** [June 9, 2017, 3:38pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/57 "2017-06-09T15:38:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kaiman](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@kaiman](https://forums.thimbleweedpark.com/u/kaiman)\
**Post date:** [June 9, 2017, 7:24pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/58 "2017-06-09T19:24:54Z")

</div>

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](https://wiki.libsdl.org/SDL_StartTextInput?highlight=%28%5CbCategoryKeyboard%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruct%29). 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/](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.

---

<div class="post-metadata">

**Author:** ![RonGilbert](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.thimbleweedpark.com/rongilbert/32/7_2.png) [@RonGilbert](https://forums.thimbleweedpark.com/u/RonGilbert)\
**Post date:** [June 9, 2017, 9:03pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/59 "2017-06-09T21:03:53Z")

</div>

> [@kaiman](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Someone](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Someone](https://forums.thimbleweedpark.com/u/Someone)\
**Post date:** [June 9, 2017, 9:40pm UTC](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718/60 "2017-06-09T21:40:45Z")

</div>

> [@RonGilbert](#):
>
> This was my experience when I first tried to around a year ago.

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](https://wiki.libsdl.org/SDL_TextInputEvent)  
And the “Tutorial” example: [https://wiki.libsdl.org/Tutorials/TextInput](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.

> [@kaiman](#):
>
> I guess if this wouldn’t be time critical, you could drop a few lines over at [https://discourse.libsdl.org/](https://discourse.libsdl.org/).

Regarding the forum: You may want to read this thread before opening a new one 🙂[SDL2 and unicode characters from key events - #18 by Jared\_Maddox - SDL Development - Simple Directmedia Layer](https://discourse.libsdl.org/t/sdl2-and-unicode-characters-from-key-events/19041/18)

Cite ([SDL2 and unicode characters from key events - #18 by Jared\_Maddox - SDL Development - Simple Directmedia Layer](https://discourse.libsdl.org/t/sdl2-and-unicode-characters-from-key-events/19041/18)):

> 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](https://wiki.libsdl.org/SDL_StartTextInput))

[Previous page](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718.md?page=2)

[Next page](https://forums.thimbleweedpark.com/t/keyboard-shortcuts/718.md?page=4)
