WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?  (Read 5348 times)

Offline Santos

  • Full Member
  • ***
  • Posts: 105
[Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« on: February 04, 2022, 06:45:49 PM »
Hello

In fact is  microcore  build up with so many extensions that is not  microcore  anymore. Anyways, I'm aware of:

Code: [Select]
/home/tc/home/.X.d/

Which works when  Xorg  is properly closed and reopened. However, what I'm trying to get is a "persistent"  setxkbmap  configuration. When keyboard is unplugged, automatically  setxkbmap  reverts itself back to defaults (en). So I have to open a new terminal and type in:

Code: [Select]
setxkbmap es

Every single time I disconnect the keyboard, which happens quite often.

Is it possible to change the default keyboard layout so it always be: es?

Thank you.
« Last Edit: February 07, 2022, 07:36:40 AM by Rich »

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #1 on: February 04, 2022, 10:27:02 PM »
Hi Santos
I think this can be done with udev.

Create a file called  /etc/udev/rules.d/98-keyboard-map.rules  containing the following:
Code: [Select]
ACTION=="add", SUBSYSTEM=="input", ENV{ID_INPUT_KEYBOARD}=="?*", RUN+="/usr/local/bin/setxkbmap es"
Now make udev aware of the new rules file:
Code: [Select]
sudo udevadm control --reload-rules
Unplug your keyboard, count to 3, and plug it back in. See if the keyboard is correctly programmed.
If it looks correct, add the  .rules  file you created to your backup. Add the  udevadm control --reload-rules
command to your  bootlocal.sh  file.

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 662

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #3 on: February 05, 2022, 07:25:02 AM »
Hi Santos
... Create a file called  /etc/udev/rules.d/98-keyboard-map.rules  containing the following:
Code: [Select]
ACTION=="add", SUBSYSTEM=="input", ENV{ID_INPUT_KEYBOARD}=="?*", RUN+="/usr/local/bin/setxkbmap es" ...
It's possible you may have to do the  RUN  part a little differently:
Sorry, see attachment, forum error.

Offline Santos

  • Full Member
  • ***
  • Posts: 105
Re: TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #4 on: February 06, 2022, 10:25:06 PM »
Hello

...
It's possible you may have to do the  RUN  part a little differently:
Sorry, see attachment, forum error.

Thank you Rich. I did tried the first udev rule you shared. But didn't worked. I will try to test it again with the corrections. To have an alternative way of doing it.

Have you tried to set the correct keyboard layout for X11.

Like this threads:

http://forum.tinycorelinux.net/index.php/topic,20065.msg124906.html#msg124906

http://forum.tinycorelinux.net/index.php/topic,24864.msg158216.html#msg158216



Thank you patrikg. It worked. The configuration file does make the keyboard layout persistent across Xorg soft and hard reset (exiting out) same with window manager or plugging keyboard in/out.

Thread can be marked as solved.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #5 on: February 07, 2022, 07:49:07 AM »
Hi Santos
... I will try to test it again with the corrections. To have an alternative way of doing it. ...
I look forward to hearing whether it works or not. Remember to disable the Xorg keyboard config file and restart
Xorg prior to trying it.

The thread has been marked as solved.

Offline Santos

  • Full Member
  • ***
  • Posts: 105
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #6 on: February 08, 2022, 10:09:32 PM »
Hello Rich.

Today I tried with the corrections you made (.txt file downloaded and checked out). But still, no change. Counted up to 3 (even tried up to ten) with keyboard unplugged,  Xorg  keyboard config file removed and  Xorg  restarted.

Am I missing something?

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #7 on: February 09, 2022, 07:15:25 AM »
Hi Santos
... Am I missing something?
Maybe. Or maybe I  missed something. Or maybe we both missed something.  :)

OK, I decided to test this out on one of my machines. I changed  RUN+=  to:
Code: [Select]
RUN+="/bin/ash -c 'touch /home/tc/KBD'"Make udev aware of the new rules file:
Code: [Select]
sudo udevadm control --reload-rulesI unplugged and replugged the keyboard. When I checked my home directory, there was an empty file called KBD, so
the rule did run. I also noticed it remembered that  NumLock  was on.

I use a US keyboard so have no need for  setxkbmap , but I have  numlockx.tcz  installed and used that for the
next test. I changed  RUN+=  to:
Code: [Select]
RUN+="/bin/ash -c 'DISPLAY=:0 /usr/local/bin/numlockx off'"I unplugged and replugged the keyboard. The  NumLock  LED briefly lit up before  numlockx  turned  NumLock  off.
So running an  X  application to change the keyboard works too.

Remember to run the  udevadm  command when you first copy the file to  /etc/udev/rules.d/
When editing the file, don't forget to hit  Save  before testing it again.
Watch your spelling, punctuation, and capitalization when making changes.
Quote
... (.txt file downloaded ...
On the off chance you changed it, I think the filenames have to end in  .rule

Offline Santos

  • Full Member
  • ***
  • Posts: 105
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #8 on: February 09, 2022, 06:02:59 PM »
Hello Rich

Followed each step very carefully, triple checked the punctuation, spelling, capitalization and saved all changes on file before closing it. And ran command to update rules.

... On the off chance you changed it, I think the filenames have to end in  .rule

Fear not. I downloaded the .txt file just to look at the content. I didn't blindly downloaded and put it in the directory. :-)

I did tested the same way you have done it. With a test file generated by  touch  . So I'm confident it is running the desired command, but maybe it is a quirk of  setxkbmap?

You can try by just changing your kbmap to something else and try to put it back on: en. With the udev rule.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #9 on: February 09, 2022, 08:48:36 PM »
Hi Santos
OK, I think I cracked it. Run the following command:
Code: [Select]
udevadm monitor --envThen unplug and replug the keyboard. You'll see  udev  print a bunch of messages. The last group is the  bind  command
for the keyboard. You want the values for  SUBSYSTEM, ID_VENDOR_ID, and ID_MODEL_ID  listed there.

Place the following in your  .rules  file with the values you found for  SUBSYSTEM, ID_VENDOR_ID, and ID_MODEL_ID.
Code: [Select]
ACTION=="bind", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="413c", ENV{ID_MODEL_ID}=="2005" RUN+="/bin/ash -c 'DISPLAY=:0 /usr/local/bin/setxkbmap es'"

Offline xor

  • Hero Member
  • *****
  • Posts: 1259
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #10 on: February 10, 2022, 12:38:21 AM »
Isn't there a script that can read the id code of the keyboard and run the necessary command accordingly!?

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #11 on: February 10, 2022, 02:27:15 PM »
Hi xor
I'm not aware of any such script.

The op said:
His keyboard sometimes becomes unplugged and forgets its settings.
When he plugs it back in, he wants it to automatically be detected and reconfigured.
If it did exist, how would you make that script run automatically?

Offline Santos

  • Full Member
  • ***
  • Posts: 105
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #12 on: February 10, 2022, 07:16:36 PM »
Hello

...
OK, I think I cracked it. Run the following command:
Code: [Select]
udevadm monitor --env...

Yes, you did. It worked this time.

Main advantage of this udev rule over the config file is there is no need to close Xorg. But is specific for each keyboard, sometimes I do change keyboards.

So, second question. Can this be more universal? Meaning: to work with any keyboard being plugged in. I just want to know whether is possible or not, with some kind of glob expanding or regex. I want to check on this myself.

Thank you.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #13 on: February 10, 2022, 07:41:17 PM »
Hi Santos
I can think of a few possibilities:
You can have multiple lines in the  .rules  file each with a different  ID_VENDOR_ID  and  ID_MODEL_ID
It will only execute the line that matches your keyboard.

Using  udevadm monitor --env
Check the  ID_MODEL  and  ID_SERIAL  fields for your keyboards. If either field contains the word  Keyboard  for
all of your keyboards, you can use that field instead of  ID_VENDOR_ID  and  ID_MODEL_ID  like this:
Code: [Select]
ENV{ID_MODEL}=="*?eyboar?*"The second ? is there to prevent the forum error, you can replace it with the letter  d  if you wish.

Offline Santos

  • Full Member
  • ***
  • Posts: 105
Re: [Solved] TCP 12 x64 How can I set up setxkbmap automatically?
« Reply #14 on: February 11, 2022, 03:26:24 PM »
Amazing, thank you Rich. You've answered all my questions.