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

Author Topic: Key detection issues.  (Read 4163 times)

0 Members and 1 Guest are viewing this topic.

spike.barnett

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Key detection issues.
« on: May 30, 2014, 09:45:01 am »
I'm seeing similar key detection issues to those referenced in:
http://en.sfml-dev.org/forums/index.php?topic=10393.0

I'm using an American English QWERTY keyboard with the most recent SFML package in the Arch Linux repos (sfml 2.1.0.4a300547f3-1).

SFML recognises that a key was pressed, but can not identify the key. This only occurs with the grave(tilde), apostrophe(quote), and numpad delete(numpad decimal) keys. I've placed my xev output below in case it helps. If it doesn't, by all means, let me know how I can provide more helpful information.


KeyPress event, serial 48, synthetic NO, window 0x1e00001,
    root 0x25c, subw 0x1e00002, time 1733558415, (44,21), root:(1245,377),
    state 0x10, keycode 49 (keysym 0x60, grave), same_screen YES,
    XLookupString gives 1 bytes: (60) "`"
    XmbLookupString gives 1 bytes: (60) "`"
    XFilterEvent returns: False

KeyPress event, serial 48, synthetic NO, window 0x1e00001,
    root 0x25c, subw 0x0, time 1733518200, (-407,111), root:(794,467),
    state 0x10, keycode 48 (keysym 0x27, apostrophe), same_screen YES,
    XLookupString gives 1 bytes: (27) "'"
    XmbLookupString gives 1 bytes: (27) "'"
    XFilterEvent returns: False

KeyPress event, serial 48, synthetic NO, window 0x1e00001,
    root 0x25c, subw 0x0, time 1733614262, (36,125), root:(1237,481),
    state 0x10, keycode 91 (keysym 0xffae, KP_Decimal), same_screen YES,
    XKeysymToKeycode returns keycode: 129
    XLookupString gives 1 bytes: (2e) "."
    XmbLookupString gives 1 bytes: (2e) "."
    XFilterEvent returns: False

spike.barnett

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Key detection issues.
« Reply #1 on: May 30, 2014, 10:10:00 am »
I've written a minimal program to demonstrate this. When the afore mentioned keys are pressed, a value of -1 is returned.

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
        window.setActive();

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            switch (event.type)
            {
                case sf::Event::Closed : window.close(); break;
                case sf::Event::KeyPressed : std::cout << event.key.code << "\n"; break;
                        }
                }
                window.clear();
                window.display();              
        }
        return 0;
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Key detection issues.
« Reply #2 on: May 30, 2014, 10:21:37 am »
It's a known problem that keyboard handling is imperfect, and we're currently investigating how to improve it (scancodes will play an important role).

See also:
https://github.com/SFML/SFML/issues/7
http://en.sfml-dev.org/forums/index.php?topic=13692.0
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

spike.barnett

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Key detection issues.
« Reply #3 on: May 30, 2014, 10:51:28 am »
It's a known problem that keyboard handling is imperfect, and we're currently investigating how to improve it (scancodes will play an important role).

Thank you for the information Nexus.

Syntactic Fructose

  • Jr. Member
  • **
  • Posts: 80
  • Overflowing stacks and eating snacks
    • View Profile
Re: Key detection issues.
« Reply #4 on: May 31, 2014, 06:34:59 pm »
I've experienced less buggy code handling input outside the event loop, I'm not sure if this is bad practice but it works 100% of the time for me.

I actually check for input using a separate function in my OpenGL SFML programs, and I've never had input issues. Gist: https://gist.github.com/Syntaf/ceb0900e446af064af72

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
AW: Re: Key detection issues.
« Reply #5 on: June 01, 2014, 11:21:25 am »
I've experienced less buggy code handling input outside the event loop, I'm not sure if this is bad practice but it works 100% of the time for me.

I actually check for input using a separate function in my OpenGL SFML programs, and I've never had input issues. Gist: https://gist.github.com/Syntaf/ceb0900e446af064af72
Your code is not very clean as sich I do not recommend it.
The reason why it has worked for you without issues, is because you use basic keys (arrows and letters), the problem in this thread however is about keys such as apostrophe and tilde, which are known to not be fully supported as already pointed out.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/