SFML community forums

Help => Window => Topic started by: santiaboy on November 17, 2013, 11:24:15 pm

Title: [SOLVED, USE THOR]"Pretty" way to remap keys
Post by: santiaboy on November 17, 2013, 11:24:15 pm
Hey there!

I am still working on my platformer (this week I'll update my project thread!) and wanted to add the option of key remapping. I thought about having some

Keyboard::Key jump
Keyboard::Key moveRight
//...

Then, I'll do Keyboad::isKeyPressed(jump). Then, when the user wants to remap it's just something like this

//..
jump = Keyboard::Escape
//..
or
//..
jump = Event::KeyEvent::code
//..

However, I'm having trouble "drawing" on screen which key represents what. Thing is, for the A-Z is simple. The Key code for A is 0, B is 1 and so on. So, I just add 65 (ascii code) and I'll have the correct letter. However, if the user presses any NUM key, or a slash, I have issues showing that on screen. I just don't know how to translate the key code to the ascii code, unless it's a big switch case (or a bunch of if/else if/else).

EDIT: 2 seconds after I posted it, I stumbled upon this: There is an event called "TextEntered" which gives you the unicode value of the character. http://www.sfml-dev.org/documentation/2.1/structsf_1_1Event_1_1TextEvent.php

So, now I am trying to use both "TextEntered" and KeyPressed to use it, and I think that will do.
Title: Re: "Pretty" way to remap keys
Post by: Nexus on November 17, 2013, 11:38:43 pm
The TextEntered event gives you the character you would type when pressing the corresponding key on the keyboard.

If you are interested in the names of the keys (such as "Space"), you won't get around a list of all possible keys and their names. That is, unless you use something existing such as Thor (http://www.bromeon.ch/libraries/thor/v2.0/doc/_input_names_8hpp.html) ;)
Title: Re: "Pretty" way to remap keys
Post by: santiaboy on November 17, 2013, 11:50:51 pm
Thanks! I was wondering that. I am seeing thor over and over again. I think I'll look more into Thor.

Marked as solved.