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

Author Topic: [potential fix] X11: Tilde key not getting detected  (Read 4502 times)

0 Members and 1 Guest are viewing this topic.

SneakySnake

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
[potential fix] X11: Tilde key not getting detected
« on: January 23, 2013, 10:24:28 pm »
I was wondering why SFML doesn't detect the tilde key, so I looked into it.

I looked at the implementation, and the underlying X11 symbol for tilde in SFML is XK_dead_grave.
I launched the xev utility, and looked at what it says when I press the tilde key.
It says XK_grave.

So I modified the implementation (both WindowImpl and InputImpl) to use XK_grave instead of XK_dead_grave, and now the Tilde key works in both cases. Another user also confirmed that it works with XK_grave for him.

Perhaps both XK_dead_grave and XK_grave could be accepted, unless there are preventing factors that I am not aware of.

EDIT: Yeah, the InputImpl got a bit hacky when taking both into account, but the WindowImpl is a clean fix.
At least that could be incorporated to make users' life easier until they wait for 2.x.

[attachment deleted by admin]
« Last Edit: January 24, 2013, 01:16:18 am by SneakySnake »

ZackTheHuman

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: X11: Tilde key not getting detected [potential fix]
« Reply #1 on: January 23, 2013, 10:31:03 pm »
I have also experienced this issue when compiling my game for Linux. After making the change you describe things are working as expected (parity with Windows). I have a standard English keyboard, standard English layout.

I'm not sure, but I think the XK_dead_grave is used for keyboard layouts such as French where accent marks are added to letters. I think possibly adding both XK_dead_grave and XK_grave is the solution to both problems.
Project Hikari Dev Blog: http://hikari.zackthehuman.com/blog/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: [potential fix] X11: Tilde key not getting detected
« Reply #2 on: January 23, 2013, 11:12:28 pm »
It seems like the realtime input and the event system handle things different for some reason, at least I get different results...
(Tested on Debian Sid)

#include <SFML/Graphics.hpp>

#include <iostream>

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
        window.setFramerateLimit(60);

        while(window.isOpen())
        {
                sf::Event event;
                while(window.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed)
                                window.close();

                        else if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Tilde)
                                std::cout << "Event" << std::endl;

                        else if(event.type == sf::Event::TextEntered && event.text.unicode < 128)
                                std::cout << "Text: " << static_cast<char>(event.text.unicode) << std::endl;
                               
                }

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Tilde))
                        std::cout << "Input" << std::endl;

                window.clear();
                window.display();
        }
}

 
I have a Swiss (German) keyboard layout:


When I press the key left of the backspace, only the input gets triggered. If I press Shift+the key in question, I get both triggered. The TextEntered on the other hand works fine and shows exactly the symbols of the keys I press.
The actual ~ symbol only shows up, when pressing [Alt Gr]+ the key in question, which triggers the input, but no event.

So I guess we could throw that into issue #7...

Note: If I apply the given patch, the tiled key won't be recognized on my system, neither by realtime input nor the event system.

Edit: The patch with both works again, but I don't think it's the way SFML will go, not even for a 'in the meantime' fix. ;)
« Last Edit: January 24, 2013, 12:58:15 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/

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: [potential fix] X11: Tilde key not getting detected
« Reply #3 on: October 11, 2013, 04:03:33 pm »
Well, Ubuntu 12.04 LTS, GCC 4.8.1, SFML just updated from repo, Tilde still not working - keycode == -1.

 

anything