YukiWorkshop / libevdevPlus

Easy-to-use event device library in C++
MIT License
6 stars 6 forks source link

Use active keymap instead of hard-coding English qwerty #2

Open piater opened 5 years ago

piater commented 5 years ago

Resource.cpp currently hard-codes an English qwerty keyboard mapping. For example, @ is represented as Shift-2. Thus, if a German qwertz keyboard mapping is active where Shift-2 is =, ydotool type @ results in = being typed. Perhaps one way forward is to follow the example of dumpkeys.

ReimuNotMoe commented 5 years ago

First I have a question, since we're emulating a new input device, does Linux kernel support different keyboards in different layouts?

I don't have much time to have a deep look, but a quick search shows (at least) X11 and Wayland supports this. I'm not sure whether this can be achieved in text console.

piater commented 5 years ago

does Linux kernel support different keyboards in different layouts?

Yes; dumpkeys reads the keyboard translation table used by the virtual consoles (and loadkeys loads them). They are developed alongside the kernel and hosted on kernel.org.

(at least) X11 and Wayland supports this.

The best way would be to load the currently-active translation table, no matter whether we are running on a vconsole, under X11, or under Wayland. They each handle their own keyboard mappings though. Therefore perhaps a good way to handle this is go back to the roots, use the vconsole keyboard layout as a lowest common denominator, and hope users configure their X/Wayland keymaps to match their console keymaps.

seiichiro0185 commented 5 years ago

+1 for this, I'm currently looking to replace xdotool with ydotool (mainly for my pass autotype script) and switching to wayland. Unfortunately this issue prevents me to do this at the moment, since e.g. z is typed as y and vice versa (I'm on a german keymap as well). I would also be Ok with using the vconsole keymap for this purpose.

ClassicOldSong commented 5 years ago

If anyone has any idea on how to get this issue solved, pull requests are always welcomed. We're currently moving to a new city and probably don't have time to deal with this in a month or so.

piater commented 5 years ago

I have scratched my itch in the meantime; check out uinputchars. @seiichiro0185, this should fully address your use case, which exactly matches mine. @ClassicOldSong, if it helps you, I can refactor my code into a library.

ClassicOldSong commented 5 years ago

@piater wow looks great, I'll check it out later