Off-Topic > Off-Topic - Tiny Core Lounge

how to automatically get xinput id of keyboard?

<< < (4/5) > >>

GNUser:
Rich,

Apparently we can't rely on the word keyboard always appearing before the first left bracket. Here's from the OpenBSD partition I have laying around for these kinds of tests:


--- Code: ---bruno@obsd:~353$ xinput list
⎡ Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                    id=4    [slave  pointer  (2)]
⎜   ↳ /dev/wsmouse0                                 id=7    [slave  pointer  (2)]
⎜   ↳ /dev/wsmouse                                  id=8    [slave  pointer  (2)]
⎣ Virtual core keyboard                       id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard                     id=5    [slave  keyboard (3)]
    ↳ /dev/wskbd                                      id=6    [slave  keyboard (3)]
--- End code ---

The correct id that needs to be automatically found in this case is 6.

I came up with this, which works in all my GNU/Linux partitions, wife's wonky Sony Vaio with GNU/Linux, and also the OpenBSD test machine above:

--- Code: ---master_id=$(LANG=C xinput list | grep -i 'master keyboard' | egrep -o 'id=[0-9]+' | egrep -o '[0-9]+')
keyboard_id=$(LANG=C xinput list $master_id | grep 'XIKeyClass' | egrep -o '[0-9]+')

--- End code ---

Rich:
Hi GNUser

--- Quote from: GNUser on September 16, 2019, 09:11:44 AM --- ... Apparently we can't rely on the word keyboard always appearing before the first left bracket. ...
--- End quote ---
It seems you also can't rely on the word  XIKeyClass  always appearing in the output. From TC4:

--- Code: ---tc@box:~$ xinput list 3
Virtual core keyboard                           id=3    [master keyboard (2)]
        Reporting 1 classes:
                Class originated from: 6
                Keycodes supported: 248

tc@box:~$
--- End code ---
TC4 dates back to 2012 so that may not be of interest. If you don't mind my being nosy, I have a couple of questions:
1. What are you working on that requires the keyboards XID?
2. What happens if a system has 2 keyboards?

GNUser:
No problem.

1. https://github.com/bdantas/iksilo
It is a little project for me and my Esperanto friends. The simplest way of typing in Esperanto is using the x-system, but a way of typing this way that works reliably on multiple UNIX-like operating systems is sorely lacking.

In order for the script to do its job, a crude keylogger (xinput test $keyboard_id) is built into the script, to keep track of the last two characters typed. I realize there are better ways to do this than with a shell script and X tools, but I'm trying to keep it as simple as possible.

2. If >1 keyboard then the autodetection won't work, but users savvy enough to have 2 keyboards can adjust the variable at the top of the script to match the id of the keyboard they want to use.

Sorry for all the trouble. This is way off-topic for Tiny Core, but I know TC users are smart so I wanted your input. We can close this thread now--what we have will work with non-ancient versions of xinput across multiple OSes  :)

Rich:
Hi GNUser

--- Quote from: GNUser on September 16, 2019, 10:09:55 AM --- ... In order for the script to do its job, a crude keylogger (xinput test $keyboard_id) is built into the script, ...
--- End quote ---
That's funny, I was going to ask if this was for a keylogger but opted to exercise some self control.


--- Quote ---Sorry for all the trouble. This is way off-topic for Tiny Core,
--- End quote ---
It's no trouble at all. The topic involves scripting, text manipulation commands, internationalization, etc. As such, I consider it
relevant to this forum. Even if considered  off topic,  that's what this particular section of the forum is here for.

Rich:
Hi GNUser
Just an FYI, Xorg supports Esperanto. I see from your link you already know ablout  setxkbmap  and probably already found
this documentation:
https://www.x.org/releases/X11R7.5/doc/input/XKB-Config.html

An example:

--- Code: ---setxkbmap -option esperanto:qwerty
--- End code ---
Found here:
https://esperanto.stackexchange.com/questions/378/how-do-i-type-the-esperanto-letters-with-accents-on-linux

A more advanced example:

--- Code: ---setxkbmap -layout "us" -variant "alt-intl" -option "lv3:lwin_switch,esperanto:qwerty"
--- End code ---
Found in the paragraph titled  setxkbmap  here:
https://www.esperanto.org.nz/learn-and-use-esperanto/how-to-type-esperanto-characters/linux/

If you install  xkeyboard-config.tcz  you'll find  epo (short for Esperanto)  listed in:
/usr/local/share/X11/xkb/rules/evdev

And I think this is used for mapping the keyboard:
/usr/local/share/X11/xkb/symbols/epo

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version