Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED, USE THOR]"Pretty" way to remap keys  (Read 2546 times)

0 Members and 1 Guest are viewing this topic.

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
[SOLVED, USE THOR]"Pretty" way to remap keys
« 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.
« Last Edit: November 17, 2013, 11:51:07 pm by santiaboy »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: "Pretty" way to remap keys
« Reply #1 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 ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: "Pretty" way to remap keys
« Reply #2 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.