Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key callback generates GLFW_KEY_UNKNOWN when not using primary keyboard layout #1748

Closed
Thraix opened this issue Aug 13, 2020 · 3 comments
Closed
Assignees
Labels
bug Bug reports and bugfix pull requests duplicate Issues duplicating another issue input Keyboard, joystick or mouse verified Reproduced or otherwise verified bugs X11
Milestone

Comments

@Thraix
Copy link

Thraix commented Aug 13, 2020

Operating System

Linux Manjaro i3 using X11

Keyboard

Corsair k70 rgb mk.2 using ckb-next driver

I've been having a problem with the key callback generating GLFW_KEY_UNKNOWN when using a keyboard layout which is not the primary one.
I have setup my keyboard with the command setxkbmap -layout us,se, that is, using us as a primary layout and se as a secondary layout. Whenever I launch my glfw program with the current layout set to se all the functional keys (ctrl, super, alt, F1-F12) report -1 as keycode.
This problem also occurs if I setup the keyboard using setxkbmap -layout se,us and starting the program with the us layout. Meaning the problem isn't with using the se layout, but using the secondary layout.

The problem occurs both using the glfw version provided by the manjaro repository, but also the latest version on GitHub.

Here is a test program I've constructed which reports the keycodes and scancodes when a user presses a button:

#include <GLFW/glfw3.h>
#include <iostream>

void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mod)
{
  glfwGetKey(window, scancode);
  std::cout << "KeyCode: " << key << " ScanCode: " << scancode << std::endl;
}

int main()
{
  if(!glfwInit())
    std::cout << "Failed to initialize GLFW" << std::endl;

  GLFWwindow* window = glfwCreateWindow(640, 480, "Invalid KeyCode", nullptr, nullptr);
  if(!window)
    std::cout <<"Failed to initialize GLFWwindow" << std::endl;

  glfwMakeContextCurrent(window);
  glfwSetKeyCallback(window, keyCallback);

  std::cout << "GLFW Version: " << glfwGetVersionString() << std::endl;

  while(!glfwWindowShouldClose(window))
  {
    glfwPollEvents();
  }
  return 0;
}

A sample output of the program is provided below:

GLFW Version: 3.3.2 X11 GLX EGL OSMesa clock_gettime evdev shared
KeyCode: -1 ScanCode: 36
KeyCode: -1 ScanCode: 133
KeyCode: -1 ScanCode: 9

If there is any more information I can provide to help debug this problem, don't hesitate to ask :)

@elmindreda elmindreda self-assigned this Aug 13, 2020
@elmindreda elmindreda added bug Bug reports and bugfix pull requests input Keyboard, joystick or mouse X11 labels Aug 13, 2020
@elmindreda
Copy link
Member

Thank you for the detailed bug report! This is hopefully the same bug that was fixed with #1598. If possible, test the default branch or the 3.3-stable branch.

@Thraix
Copy link
Author

Thraix commented Aug 13, 2020

I though I was using the default branch but apparently I needed to specify where the glfw 3.3.3 library was located when compiling. So after getting the 3.3-stable downloaded and installed correctly it now reports the correct key codes (not -1). Sorry for wasting your time by not installing the latest version correctly and thanks :)

@Thraix Thraix closed this as completed Aug 13, 2020
@elmindreda
Copy link
Member

No worries, thank you for the follow-up!

@elmindreda elmindreda added duplicate Issues duplicating another issue verified Reproduced or otherwise verified bugs labels Aug 13, 2020
@elmindreda elmindreda added this to the None milestone Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports and bugfix pull requests duplicate Issues duplicating another issue input Keyboard, joystick or mouse verified Reproduced or otherwise verified bugs X11
Projects
None yet
Development

No branches or pull requests

2 participants