ubuntu c++ how get the name of the current active keyboard

68 Views Asked by At

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

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

1

There are 1 best solutions below

2
Hadi On

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.