LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   How can I switch between keymaps without changing locale? (https://www.linuxquestions.org/questions/slackware-14/how-can-i-switch-between-keymaps-without-changing-locale-4175515504/)

astrogeek 08-19-2014 05:12 PM

How can I switch between keymaps without changing locale?
 
I am learning a new language. All my Slackware boxes are UTF-8 and I am using ter-v16n for my console font, and have all other fonts needed when running X apps. All of this is working flawlessly. I can see the desired character sets in console and under X.

I am a Vim user and can easily type in an alternate character set by using Vim's set keymap feature. I can then switch between the alternate keymap and the default very simply with Ctrl-6. This has been my primary input method.

So far no problems...

But what I would like to do is to be able to switch between ASCII (or default keymap) and a chosen alternate in console if possible, and in X definitely. In other words, while typing this post I would like to be able to hit a hot-key and изменится на русском, then hit it again and change back, as easily as within Vim.

In console I can set a new keymap with loadkeys, but I have not figured out how to easily switch between the new one and the default - or if it is even possible. This seems to be geared toward a single keymap set at boot but not easily changed later.

But more importantly, I would like to be able to type my emails and post to forums in Firefox and write documents in LibreOffice, etc... switching at will between two keymaps.

I have read the Slackdocs localization page, multi-keyboard layout section, but I have not been able to make that work. The man pages for setxkbmap and loadkeys are dog-eared now, but I have only managed to confuse myself... so here I am, hat in hand...

I suspect this should be easier than I am making it. Can someone please point me in the right direction.

*** UPDATE ***

After fighting it all day took a short walk... and a cup of tea later...

Code:

setxkbmap -option grp:alt_shift_toggle us,ru -variant ',phonetic' -display 0:0
Which gets me going for X! I can translate this into xorg.conf options I hope...

For others as slow as myself, the phonetic variant gives you the same mappings as ru-yawerty in console and russian-yawerty in Vim, very important!

Now if I can get to the same point with the console all the better, but X was my roadblock...

bormant 08-19-2014 10:09 PM

Quote:

I can translate this into xorg.conf options
Please, see http://slackware.osuosl.org/slackwar..._AND_HINTS.TXT near mention of 90-keyboard-layout.conf and comments in that file.
I use caps to switch layouts and shift_caps to lock caps for 2 reasons: 1) with grp:alt_shift_toggle you cannot use Alt+Shift+key combos in any X application because X eats it on keypress not on release, 2) to press one key is better than two ;-)

If you add "switch" to grp, you can type with another layout with AltGr (right alt) pressed.

If I am right, kbd package has one non utf8 ru yawerty keymap. It can be converted to utf8.

Please note, yawerty layout is rare and was used on old machines. Currently Russian keyboards usually engraved with ruwin (йцукен) key labels. So for ruwin it can be, for ex.
/etc/rc.d/rc.keymap
Code:

#!/bin/sh
# Load the keyboard map. More maps are in /usr/share/kbd/keymaps.
if [ -x /usr/bin/loadkeys ]; then
    echo "Loading keybord layout, CapsLock to toggle"
    /usr/bin/loadkeys ruwin_cplk-UTF-8
fi

/etc/X11/xorg.conf.d/90-keyboard-layout.conf
Code:

...
Option "XkbLayout" "us,ru"
Option "XkbOptions" "grp:caps_toggle,grp:switch,terminate:ctrl_alt_bksp"


bormant 08-19-2014 10:29 PM

Console layouts usually use AltGr shift to define second layout, so to identify the toggle key may be useful something like
Code:

zgrep AltGr_Lock /usr/share/kbd/keymaps/i386/qwerty/ruwin_cplk-UTF-8.map.gz
keycode  58 = AltGr_Lock

58 is scan code for CapsLock key.

bormant 08-19-2014 10:39 PM

It is a good idea to read a keymap file itself. Usually it has useful comments about content including switching keys used. less is enough:
less /usr/share/kbd/i386/qwerty/ru-yawerty.map.gz
less /usr/share/kbd/i386/qwerty/ruwin_cplk-UTF-8.map.gz
...

astrogeek 08-19-2014 11:24 PM

Спасибо bormant!

Quote:

Originally Posted by bormant (Post 5223934)
Please, see http://slackware.osuosl.org/slackwar..._AND_HINTS.TXT near mention of 90-keyboard-layout.conf and comments in that file.

Yes I have already adapted the 90-keyboard-layout.conf and now have my X environment working well! I don't know why that seemed so difficult to get going... first time confusion I suppose!

Quote:

Originally Posted by bormant (Post 5223934)
I use caps to switch layouts and shift_caps to lock caps for 2 reasons: 1) with grp:alt_shift_toggle you cannot use Alt+Shift+key combos in any X application because X eats it on keypress not on release, 2) to press one key is better than two ;-)

If you add "switch" to grp, you can type with another layout with AltGr (right alt) pressed.

I have not hit any snags with Alt-Shift yet, but CapsLock makes more sense to me as well so I think I will adopt your convention. If I can set it same for console and X I'll be a happy camper!

Quote:

Originally Posted by bormant (Post 5223934)
If I am right, kbd package has one non utf8 ru yawerty keymap. It can be converted to utf8.

Please note, yawerty layout is rare and was used on old machines. Currently Russian keyboards usually engraved with ruwin (йцукен) key labels. So for ruwin it can be, for ex.
/etc/rc.d/rc.keymap

I need to stick with the phonetic layout as I do not have an йцукен engraved keyboard and would be hopelessly lost! I have been using yawerty layout in Vim for the past month or two and find it pretty easy. If I can eventually get a йцукен engraved keyboard I'll make the switch.

And yes, there seems to be only the non-UTF-8 yawerty in the kbd package. I know that I have read about generating UTF-8 keymaps from non-UTF-8 in all my reading - but if you know the quick path to doing that I would much appreciate it!

Quote:

Originally Posted by bormant (Post 5223942)
Console layouts usually use AltGr shift to define second layout, so to identify the toggle key may be useful something like
Code:

zgrep AltGr_Lock /usr/share/kbd/keymaps/i386/qwerty/ruwin_cplk-UTF-8.map.gz
keycode  58 = AltGr_Lock

58 is scan code for CapsLock key.

Thanks for the scan code, I think I can easily enough figure out how to change that, if I can get a UTF-8 yawerty set up.

I knew from the man pages that the keymaps were line oriented text files, but I had not actually looked inside one (intended to but had too many pending items queued in my lone brain cell!).

Еще раз спасибо!

bormant 08-20-2014 01:21 AM

Quote:

I need to stick with the phonetic layout as I do not have an йцукен engraved keyboard and would be hopelessly lost! I have been using yawerty layout in Vim for the past month or two and find it pretty easy.
ru(phonetic) flaw is that key positioning doesn't reflect Russian symbol usage frequency. Your fingers will tie knots instead of flying. Also typewriters use traditionally "йцукен" (with punctuation and shifted numbers in numeric row).
Now you know.

If you still stay with ru-yawerty, I'll can try to write ru-yawerty_cplk-UTF-8 layout as ru(phonetic) or ru-yawerty (they has minor differences).

astrogeek 08-20-2014 01:46 AM

Quote:

Originally Posted by bormant (Post 5223984)
ru(phonetic) flaw is that key positioning doesn't reflect Russian symbol usage frequency. Your fingers will tie knots instead of flying. Also typewriters use traditionally "йцукен" (with punctuation and shifted numbers in numeric row).
Now you know.

If you still stay with ru-yawerty, I'll can try to write ru-yawerty_cplk-UTF-8 layout as ru(phonetic).

Ha! I think it will be some time before my fingers are flying на русском (по-русски?)! ;)

I appreciate your encouragement but I think that yawerty/phonetic is my only way forward at this time. I am already moderately proficient with it in Vim as well - trying to memorize a new keyboard layout without the phonetic cues would really tie me in knots! After I learn to think and speak the language I will be better able to improve my typing skills and will get a ruwin-engraved keyboard too!

I also appreciate your offer to work up a UTF-8 ru-yawerty, that is very kind! I have been studying the ru-yawerty and ruwin-cplk-UTF-8 for the past hour or so, planning a strategy that could lead to success. I also searched for any automated tools for doing that but did not see anything easier than simply writing it by hand.

So if you have an easier way of doing it, I accept! But if you will have to edit it by hand I would not ask you to put in that amount of work on it - I can probably work my way through it and maybe learn something in the process.

Thanks!

astrogeek 08-20-2014 02:29 AM

Quote:

Originally Posted by bormant (Post 5223984)
ru(phonetic) flaw is that key positioning doesn't reflect Russian symbol usage frequency. Your fingers will tie knots instead of flying. Also typewriters use traditionally "йцукен" (with punctuation and shifted numbers in numeric row).
Now you know.

If you still stay with ru-yawerty, I'll can try to write ru-yawerty_cplk-UTF-8 layout as ru(phonetic) or ru-yawerty (they has minor differences).

I was afraid that I might seem dismissive of your advice for using non-yawerty keyboard layout, and to be fair I had not actually explored it beyond trying a few keys, so I decided to load ruwin-cplk-UTF-8 and give it a try.

I generated a map of all keys shifted and un-shifted in order of US alphabet/keymappings so I could see how much different they actually were...

Wow! They are different!

Without the Cyrillic engraving I would be completely lost on my US keyboards! So I think the phonetic "mapping" is my only alternative at this time.

Thanks!

bormant 08-20-2014 03:19 AM

Quote:

I can probably work my way through it and maybe learn something in the process
To modify ru-yawerty.map from it's koi8-r to utf8

1) unzip it in another file, for ex.
Code:

# cd /usr/share/kbd/i386/qwerty
# zcat ru-yawerty.map.gz > ru-yawerty_cplk-UTF-8.map

2) replace octal symbol codes from koi8-r to unicode representation by this table (first column by second)
Code:

0243 U+0451 ё
 0263 U+0401 Ё
+0337 U+044A ъ
+0336 U+0447 ч
+0376 U+0427 Ч
+0321 U+044F я
+0361 U+042F Я
+0327 U+0432 в
+0367 U+0412 В
+0305 U+0435 е
+0345 U+0415 Е
+0322 U+0440 р
+0362 U+0420 Р
+0324 U+0442 т
+0364 U+0422 Т
+0331 U+044B ы
+0371 U+042B Ы
+0325 U+0443 у
+0365 U+0423 У
+0311 U+0438 и
+0351 U+0418 И
+0317 U+043E о
+0357 U+041E О
+0320 U+043F п
+0360 U+041F П
+0333 U+0448 ш
+0373 U+0428 Ш
+0335 U+0449 щ
+0375 U+0429 Щ
+0301 U+0430 а
+0341 U+0410 А
+0323 U+0441 с
+0363 U+0421 С
+0304 U+0434 д
+0344 U+0414 Д
+0306 U+0444 ф
+0346 U+0424 Ф
+0307 U+0433 г
+0347 U+0413 Г
+0310 U+0445 х
+0350 U+0425 Х
+0312 U+0439 й
+0352 U+0419 Й
+0313 U+043A к
+0353 U+041A к
+0314 U+043B л
+0354 U+041B Л
+0300 U+044E ю
+0340 U+042E Ю
+0334 U+044D э
+0374 U+042D Э
+0332 U+0437 з
+0372 U+0417 З
+0330 U+044C ь
+0370 U+042C Ь
+0303 U+0446 ц
+0343 U+0426 Ц
+0326 U+0436 ж
+0366 U+0416 Ж
+0302 U+0431 б
+0342 U+0411 Б
+0316 U+043D н
+0356 U+041D Н
+0315 U+043C м
+0355 U+041C М

3) assign layout switch to CapsLock key, caps lock to Shift+Caps combo

3.1) update "keycode 100" line to
Code:

                keycode 100 = AltGr
3.2) replace "keycode 58" line with
Code:

                keycode  58 = AltGr_Lock
        shift  keycode  58 = Caps_Lock
altgr  shift  keycode  58 = Caps_Lock

4) update description in head comment at least about switching

5) (optional) compress keymap with gzip
# gzip ru-yawerty_cplk-UTF-8.map

6) use as usual

bormant 08-20-2014 05:29 AM

Some notes for keymaps.

Russian keymaps use this layout (placement of Ёё and punctuation may vary, but other letters always in these places)
Code:

qwerty <-> йцукен
+-41+--2+--3+--4+--5+--6+--7+--8+--9+-10+-11+-12+-13+-----14+
|~ Ё|!  |@ "|# №|$ ;|%  |^ :|& ?|*  |(  |)  |_  |+  | BACK- |
|` ё|1  |2  |3  |4  |5  |6  |7  |8  |9  |0  |-  |=  | SPACE |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
+---15+-16+-17+-18+-19+-20+-21+-22+-23+-24+-25+-26+-27+---43+
| TAB |Q Й|W Ц|E У|R К|T Е|Y Н|U Г|I Ш|O Щ|P З|{ Х|} Ъ||    |
|    |q й|w ц|e у|r к|t е|y н|u г|i ш|o щ|p з|[ х|] ъ|\    |
+-----+---+---+---+---+---+---+---+---+---+---+---+---+-----+
+-----58+-30+-31+-32+-33+-34+-35+-36+-37+-38+-39+-40+-----28+
| CAPS  |A Ф|S Ы|D В|F А|G П|H Р|J О|K Л|L Д|: Ж|" Э| ENTER |
| LOCK  |a ф|s ы|d в|f а|g п|h р|j о|k л|l д|; ж|' э|      |
+-------+---+---+---+---+---+---+---+---+---+---+---+-------+
+-------42+---+---+---+---+---+---+---+---+---+---+-------54+
| SHIFT  |Z Я|X Ч|C С|V М|B И|N Т|M Ь|< Б|> Ю|? ,| SHIFT  |
|        |z я|x ч|c с|v м|b и|n т|m ь|, б|. ю|/ .|        |
+---------+---+---+---+---+---+---+---+---+---+---+---------+

There are old Russian keyboards with phonetic layout where English letters engraved on accordant Russian letters, on Russian [f] - F, Russian [d] - D, and so on, for example: http://www.leningrad.su/museum/34/is1030-3.jpg

If you use phonetic/yawerty keymap on qwerty keyboard you get this horror and nightmare:
Code:

qwerty <-> яверты
+-41+--2+--3+--4+--5+--6+--7+--8+--9+-10+-11+-12+-13+-----14+
|~ Ю|!  |@  |# ё|$ Ё|%  |^  |&  |*  |(  |)  |_ ъ|+ Ч| BACK- |
|` ю|1  |2  |3  |4  |5  |6  |7  |8  |9  |0  |-  |= ч| SPACE |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
+---15+-16+-17+-18+-19+-20+-21+-22+-23+-24+-25+-26+-27+---43+
| TAB |Q Я|W В|E Е|R Р|T Т|Y Ы|U У|I И|O О|P П|{ Ш|} Щ|| Э  |
|    |q я|w в|e е|r р|t т|y ы|u у|i и|o о|p п|[ ш|] щ|\ э  |
+-----+---+---+---+---+---+---+---+---+---+---+---+---+-----+
+-----58+-30+-31+-32+-33+-34+-35+-36+-37+-38+-39+-40+-----28+
| CAPS  |A А|S С|D Д|F Ф|G Г|H Х|J Й|K К|L Л|:  |"  | ENTER |
| LOCK  |a а|s с|d д|f ф|g г|h х|j й|k к|l л|;  |'  |      |
+-------+---+---+---+---+---+---+---+---+---+---+---+-------+
+-------42+---+---+---+---+---+---+---+---+---+---+-------54+
| SHIFT  |Z З|X Ь|C Ц|V Ж|B Б|N Н|M М|<  |>  |?  | SHIFT  |
|        |z з|x ь|c ц|v ж|b б|n н|m м|,  |.  |/  |        |
+---------+---+---+---+---+---+---+---+---+---+---+---------+

Please keep this in mind and run from yawerty keymap as soon as possible.
I think colored keyboard stickers can help significantly.

astrogeek 08-21-2014 06:41 PM

Привет бормант!

Thank you very much for the well presented encoding and layout info! I also appreciate that you posted it so quickly, and apologize for the delay responding to you! Using your info I was able to produce an ru-yawerty_cplk-UTF-8.map file over morning tea yesterday - very quickly! I had already begun but your very clear info and instructions made it very easy!

Unfortunately, shortly after finishing and installing it I had to leave unexpectedlay and am only now returning to it.

I have checked the keys 100% and find no errors in your encoding or my typing! I have now added it to my main three machines that I will use it on and the console keymap works without problem on all of them. I had not realized it, but the need to have it on more than one machine (laptop and desktops) makes it less likely that I would have a proper Russian keyboard or stickers on them all, so still yawerty for me at this time. I will have to save fleeing from it for some other time. ;)

However, I am shopping for a йцукен keyboard and will get one at my first good opportunity!

I found that the Xorg configuration works well on some of my machines, but have opted for shift_caps_toggle instead of caps_switch. I found that caps_switch did not work well with my own typing habits and keyboards and needed a toggle instead of a switch. I also use a Logitech wireless keyboard and touchpad on one of them and it would not work with caps_switch at all for some reason. Just as well because I find I frequently hit the caps lock on it unintentionally any way.

Finally, I am having problems with the Xorg setup on the third machine, probably not related to the keymap. It is the only Slackware64 machine and has the Nvidia 304.xxx driver. I cannot make it work from the xorg.conf, but it does work if enabled with setxkb after X is started. I also find a segmentation fault as the final Xorg.log entry after shutdown when enabled from the xorg.conf. Not sure what that is about but will sort it out as time permits.

So, to summarize - I am a happy camper! I really appreciate the work you must have put in to produce the encoding and layout matrix, very helpful - and successful!

Спасибо!

bormant 08-22-2014 12:03 AM

Quote:

instead of caps_switch
Please note the difference between *_toggle and *_switch -- first acts as Lock keys while second acts only while key is down (as Shift key). switch itself without any prefix_ is AltGr or right Alt key.

I talked about "grp:caps_toggle,grp:switch" for xkb, not caps_switch. With these settings you have 2 variants:

1) pressing CapsLock switches layout permanently:
English now<CapsLock down><CapsLock up>теперь по-русски<CapsLock down><CapsLock up>English again

2) holding AltGr (right Alt) switches layout temporally:
English now<AltGr down and hold>пара слов<AltGr up>English again

*) Shift+CapsLock acts as CapsLock.

Second is very useful when you need some another layout symbols in ton of text. So "caps_switch" and "caps_toggle" are very different. For the list of available "grp:" combos please see /etc/X11/xkb/rules/.

These setting ("grp:caps_toggle,grp:switch") are the same as (3) in above message #9 for console layout.

All above is for clarity only, any option at your own choise.

Quote:

So, to summarize - I am a happy camper!
Great! Отлично!

astrogeek 08-22-2014 02:19 AM

Ah! I must have mis-read that! I looked at options in xkeyboard-config man page but was unaware of the definitions in /etc/X11/xkb/rules/... (the keymap stuff especially in X is still new to me!) I was not seeing the behavior you described, either in the man page or on the machine. I have now changed to caps_toggle and switch and this is exactly what I need (except for the wireless keyboard/touchpad I mentioned - I don't care much for it anyway so maybe use an alternate until I replace it).

But now my main machine (laptop) is exactly as I wanted in both console and Xorg!

Thanks for your continuing help!

Да! Отлично!

By the way, I went back to look at the museum photo of the keyboard/computer but you have removed it. I wanted to grab the image for the nameplate info which I thought was interesting. Any chance to provide that link again, пожалуйста?

bormant 08-22-2014 03:17 AM

Quote:

Any chance to provide that link again
As I can see, the link to keyboard photo is still in message #10 of this thread:
http://www.leningrad.su/museum/34/is1030-3.jpg

Links to the pages with this image:
http://www.leningrad.su/museum/show_big.php?n=1437
http://www.leningrad.su/museum/show_calc.php?n=333

Link to whole museum site (has English version too):
http://www.leningrad.su/museum/

astrogeek 08-22-2014 01:37 PM

Quote:

Originally Posted by bormant (Post 5225258)
As I can see, the link to keyboard photo is still in message #10 of this thread:
http://www.leningrad.su/museum/34/is1030-3.jpg

Links to the pages with this image:
http://www.leningrad.su/museum/show_big.php?n=1437
http://www.leningrad.su/museum/show_calc.php?n=333

Link to whole museum site (has English version too):
http://www.leningrad.su/museum/

I scrolled the page several times and could not find the link... too much input the past few days! Thanks for the additional links too!

I am going to mark this thread solved and really appreciate your first-class help! When my use of the language improves I will send you a note по-русски! Perhaps from an йцукен keyboard! ;)

Еще раз спасибо!


All times are GMT -5. The time now is 01:22 PM.