0

In Ubuntu C++ how can I get the name of the current keyboard?

I want to use a c++ program not the command line.

user3443063
  • 1,455
  • 4
  • 23
  • 37

1 Answers1

1

For a proper solution you can use D-bus (used for inter-process communication)

sudo apt-get install libdbus-1-dev libdbus-cpp-dev

Alternatively you can try a bit of a hacky solution by installing and adding xkblayout-state to your path and then have a C++ wrapper:

#include <cstdlib>

int main() {
    std::system("xkblayout-state print \"%s\"");
    return 0;
}

The above will print out the layout of the keyboard.

Hadi
  • 945
  • 3
  • 10
  • 31
  • 2
    I would say both solutions still use the command line and neither store the name of the keyboard in something representing a C++ string. So this is not an answer – Pepijn Kramer May 26 '23 at 14:20
  • I'm not sure if there is a library that would be designed for this task in C/C++. C++ wouldn't have a way of knowing a keyboard that is attached to the system. – Hadi May 31 '23 at 18:19