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

Author Topic: Enter key from Numpad not working (contrary to "main" Enter key)  (Read 6383 times)

0 Members and 1 Guest are viewing this topic.

sfml_noob

  • Newbie
  • *
  • Posts: 5
  • Arch Linux - g++ 10.2.0
    • View Profile
    • Email
Enter key from Numpad not working (contrary to "main" Enter key)
« on: November 17, 2020, 06:56:13 pm »
Hi!
I'm following the book "Beginning C++ Game Programming" from John Horton.
One of the first project uses the Enter key:

// Start the game
if (Keyboard::isKeyPressed(Keyboard::Enter))
{
...
}
It's working with the central Enter key, but I'm surprised that pressing the right Enter key (the one with the numpad) does nothing.
Is it possible to get the Numpad Enter key working?
Thanks!

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Enter key from Numpad not working (contrary to "main" Enter key)
« Reply #1 on: November 17, 2020, 07:47:03 pm »
well, that's rather strange. I was going to say that Keyboard::Enter references only the main key (Return), but I just went to the docs to search which would be the key to numpad enter and there is no mention to it. as the docs mention "Enter | The Enter/Return keys", with an "s", I'm guessing that it could be a bug  ???
Visit my game site (and hopefully help funding it? )
Website | IndieDB

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Enter key from Numpad not working (contrary to "main" Enter key)
« Reply #2 on: November 17, 2020, 09:47:49 pm »
I've tested this, and it works for me. I'm using Visual Studio 2019 with the latest revision of SFML. Can you share which platform you're using (OS/compiler etc) so other people can try and reproduce the problem? Also, what's your keyboard layout?

sfml_noob

  • Newbie
  • *
  • Posts: 5
  • Arch Linux - g++ 10.2.0
    • View Profile
    • Email
Re: Enter key from Numpad not working (contrary to "main" Enter key)
« Reply #3 on: November 18, 2020, 07:55:42 am »
Thanks for the reply!
I'm on Arch linux. The compiler is g++ 10.2.0.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Enter key from Numpad not working (contrary to "main" Enter key)
« Reply #4 on: November 18, 2020, 08:31:36 am »
Looks like we only handle XK_Return and not XK_KP_Enter on Linux.
While on Windows, I think the VK_RETURN applies for both the regular enter key and the numpad enter key.

Maybe there's a setting somewhere to change this behavior?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sfml_noob

  • Newbie
  • *
  • Posts: 5
  • Arch Linux - g++ 10.2.0
    • View Profile
    • Email
Re: Enter key from Numpad not working (contrary to "main" Enter key)
« Reply #5 on: November 18, 2020, 09:08:06 am »
I've found a thread about this problem (unrelated to SFML: it's "Juce", a cross-platform music software).
Maybe it can help...
https://forum.juce.com/t/keypad-enter-key-doesnt-work-like-enter-key/10965/3

sfml_noob

  • Newbie
  • *
  • Posts: 5
  • Arch Linux - g++ 10.2.0
    • View Profile
    • Email
Re: Enter key from Numpad not working (contrary to "main" Enter key)
« Reply #6 on: November 19, 2020, 02:59:37 pm »
I'm more advanced in the book. Now I've found that with another method, both Enter keys are detected!

 
while (window.pollEvent(event))
         {
                if (event.type == Event::KeyPressed)
               {
                    // Pause a game while playing
                    if (event.key.code == Keyboard::Return && state == State::PLAYING)
                    {
                        state = State::PAUSED;
                }
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Enter key from Numpad not working (contrary to "main" Enter key)
« Reply #7 on: November 20, 2020, 10:08:29 am »
We do handle XK_KP_Enter for events, but not for the isKeyPressed one.

Not sure if we can easily fix this, because the isKeyPressed is a mapping from sf::Keyboard::Key to symKey, while the event is a mapping from symKey to sf::Keyboard::Key, so for the latter we can assign multiple symKeys to the same SFML key code.

I guess this will be solved with scan codes that differentiate between numpad enter and normal enter.
« Last Edit: November 20, 2020, 10:14:03 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/