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

Author Topic: Keyboard input  (Read 4484 times)

0 Members and 1 Guest are viewing this topic.

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Keyboard input
« on: December 20, 2014, 11:50:52 am »
Hey everyone,

Recently I implemented the SFML keyboard system, but I'm having issues detecting special keys such as !@#$%^&*. Those keys are on shift on my particular keyboard, but I'm well aware that they are on different locations on different keyboards (for example: it's on 8 without shift in Belgium).
Is there any universal way to detect the special keys, preferably by ASCII code?

Thanks in advance,
Anasky

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Keyboard input
« Reply #1 on: December 20, 2014, 12:03:00 pm »
SFML currently has some issues with special characters and will improve on it in the future, see issue #7.
If you want text input, use the TextEntered event.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Keyboard input
« Reply #2 on: December 20, 2014, 12:34:15 pm »
I'm already using the SFML events for regular text, as well as enters etc. Only issue is the special characters. Any idea how long it'll take for issue #7 to be fixed?

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Keyboard input
« Reply #3 on: December 20, 2014, 06:46:03 pm »
You should be aware that there is a difference between sf::Event::KeyPressed events and sf::Event::TextEntered events.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Anasky

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Keyboard input
« Reply #4 on: December 21, 2014, 01:49:30 pm »
Quote
} else if (event.type == sf::Event::TextEntered){
            unsigned char t = event.key.code;
            KeyDown(event.text.unicode);
         } else if (event.type == sf::Event::KeyPressed){
            unsigned int keycode = event.key.code;
            if (keycode == 88){
               if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt) || sf::Keyboard::isKeyPressed(sf::Keyboard::RAlt)){
                  Main.StopLooping = true;
                  running = false;
               }
            }
            if (keycode == 27 || keycode == 49 || keycode == 52 || keycode == 57 || (keycode >= 71 && keycode <= 74)){
               SpecialKeyDown(event.key.code);
            }

Yeah, I know :) But as you can see, I have to check for specific keycodes in the KeyPressed for ! etc, but I know that won't work on different keyboards :(

 

anything