Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

Easy accents in X11

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
34 posts
  • 1
  • 2
  • Next
Author
Message
cfaun
n00b
n00b
Posts: 63
Joined: Sat Dec 25, 2004 2:40 pm

Easy accents in X11

  • Quote

Post by cfaun » Sat Jan 15, 2005 12:31 am

The author takes no responsibility for anything that may go wrong.

Face it, cutting and pasting odd characters (such as á) can be a pain. To fix this, a program called xmodmap (it comes with X) can be used to help out. Basically, you can configure your computer to make it so that when an unused key, called a dead key (such as a windows key) is held down while pressing a normal key, instead of outputting the normal character, X11 will output the strange character. For instance, I have my computer configured that when I hold down the left windows key and press the "a" key, á is outputted.

First, determine which key you want to use as your dead key. Now, at a console, start the program xev. Press that key. Now close, xev, using only the mouse (don't use ALT-F4 or CONTROL-C). Although there will be some useless information after it, you should see something like the following:

Code: Select all

KeyRelease event, serial 30, synthetic NO, window 0x2400001,
    root 0x8d, subw 0x0, time 8688866, (-93,-115), root:(730,348),
    state 0x2000, keycode 115 (keysym 0xff7e, Mode_switch), same_screen YES,
    XKeysymToKeycode returns keycode: 93
    XLookupString gives 0 bytes:
Take note of the keycode, which is, in this case, 115.

Now, create a file, preferably with execute permissions, called "fix.sh". In it, add the following:

Code: Select all

#!/usr/bin/bash
xmodmap -e 'keycode 115 = Mode_switch'
Now, for one of the keys that you want something to happen with when pressed in conjunction with the dead key. Start xev again and press your key. Close it like before and you should see something like this:

Code: Select all

KeyPress event, serial 30, synthetic NO, window 0x2400001,
    root 0x8d, subw 0x0, time 9014225, (792,179), root:(795,208),
    state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XmbLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False
Take note of the keycode (in this case, 38 ) and what it says after keysym and 0xsomething (in this case, a). Now do the same with holding down shift and then the key. The keycodes should be the same, but there will be a different keysym. Take note of what it is.

Now, you must determine what you want the computer to output if you hold down the deadkey and the other key. In addition, you need to determine what you want the computer to output if you hold down the deadkey, the shift key, AND the other key. The list of options can be found in the file /usr/include/X11/keysymdef.h.

Now append a line to "fix.sh" with the following format:

Code: Select all

xmodmap -e 'keycode KEYCODE = NORMAL_KEY KEY_WITH_SHIFT DEADKEY_AND_KEY DEADKEY_SHIFT_AND_KEY'
Replace KEYCODe with the key's keycode, NORMAL_KEY with the keysym for when the key is pressed without modifiers (for instance, "a" (no quotes) for the A key), KEY_WITH_SHIFT with the keysym for the key with shift help down (for instance, "A"), DEADKEY_AND_KEY with what you want to happen when the deadkey and the key are held down together (for instance, aacute, which is the á character), and DEADKEY_AND_SHIFT_AND_KEY for what you want to happen when the deadkey, shift, and the key are held down together (for instance, Aacute, which is Á).

Repeat for all the other characters that you want. An example of a finished fix.sh is as follows, which can be used for inputting characters of the spanish language:

Code: Select all

xmodmap -e 'keycode 115 = Mode_switch'
xmodmap -e 'keycode 38 = a A aacute Aacute'
xmodmap -e 'keycode 26 = e E eacute Eacute'
xmodmap -e 'keycode 31 = i I iacute Iacute'
xmodmap -e 'keycode 32 = o O oacute Oacute'
xmodmap -e 'keycode 30 = u U uacute Uacute'
xmodmap -e 'keycode 57 = n N ntilde Ntilde'
xmodmap -e 'keycode 61 = slash question questiondown questiondown'
xmodmap -e 'keycode 10 = 1 exclam 1 exclamdown'
Now, run your fix.sh file and it will start working (unless you get syntax errors, in which case, you may want to correct over the offending parts ). If you like it, you can set it to run automatically upon the start up of your desktop environment. For example, in kde, you would copy it to .kde/Autostart in your home directory.

Note that typing a key that you did not specify while holding down the deadkey will result in an odd character being outputted.
This sig intentionally left blank
Top
Gherald
Veteran
Veteran
User avatar
Posts: 1399
Joined: Mon Aug 23, 2004 10:19 pm
Location: CLUAConsole

  • Quote

Post by Gherald » Sat Jan 15, 2005 2:05 am

Is there no possible way to get it to behave exactly as Alt+numpadkeys does on Windows?
US.EF.UL | mine | Stage 1/3 | console login | use cd -
Top
cfaun
n00b
n00b
Posts: 63
Joined: Sat Dec 25, 2004 2:40 pm

  • Quote

Post by cfaun » Sat Jan 15, 2005 2:21 am

I am almost certain that it is possible. However, it would involve writing a fairly complex program that would involve intercepting and creating x events (I have no idea how to do this). But, in my opinion, this way is easier: to get ñ, what is easier, ALT+6549546194897461564987964242423, or windows-key+n?
This sig intentionally left blank
Top
Gherald
Veteran
Veteran
User avatar
Posts: 1399
Joined: Mon Aug 23, 2004 10:19 pm
Location: CLUAConsole

  • Quote

Post by Gherald » Sat Jan 15, 2005 2:52 am

On my keyboard it would have to be the former, seeing as I don't have a windows key : )
US.EF.UL | mine | Stage 1/3 | console login | use cd -
Top
Ox-
Guru
Guru
User avatar
Posts: 305
Joined: Thu Jun 19, 2003 4:43 am

  • Quote

Post by Ox- » Sat Jan 15, 2005 3:23 am

I just use put:

Code: Select all

Option "XkbLayout"  "us_intl"
in /etc/X11/xorg.conf, which might be what you want as well freeix.

Under that layout, the dead keys are the accents themselves.

So, to get ñ you need to press ~ and then n.

The drawback to this approach is getting used to typing ~~ to get a single ~. This can be annoying sometimes, especially with double-quotes. It's made worse by xkb being a little brain dead. If I type ~t it should display it just like that, but instead xkb beeps at you and you have to type ~~t. There was a thread on the Tips and Tricks forum on how to fix that, but I haven't done so yet.
Top
cfaun
n00b
n00b
Posts: 63
Joined: Sat Dec 25, 2004 2:40 pm

  • Quote

Post by cfaun » Sat Jan 15, 2005 3:15 pm

freeix wrote:On my keyboard it would have to be the former, seeing as I don't have a windows key : )
True, but this can be done with any key that you don't use.Thus, if you don't use caps-lock, the scroll lock key, the num-lock key (you can make it on by default), the right control key, the F9 key, etc, this approach will work, although depending on what you do, it may cause inconvenience.

I did try the traditional approach that Ox- mentioned. And although all console beeping can be turned off with "term -blength 0" (or something like that), it is inconvenient for those who use quotes, backquotes and tildes a not. In programming, I have to use ',"", and ` quite frequently...
This sig intentionally left blank
Top
Gherald
Veteran
Veteran
User avatar
Posts: 1399
Joined: Mon Aug 23, 2004 10:19 pm
Location: CLUAConsole

  • Quote

Post by Gherald » Sat Jan 15, 2005 6:53 pm

Are you aware of $( ) in bash? It's easier to read, and nestable.
US.EF.UL | mine | Stage 1/3 | console login | use cd -
Top
cfaun
n00b
n00b
Posts: 63
Joined: Sat Dec 25, 2004 2:40 pm

  • Quote

Post by cfaun » Sat Jan 15, 2005 7:38 pm

No, I'm not entirely sure what you are talking about. In my ignorance I thought $ was only used in bash to dereference variables...
This sig intentionally left blank
Top
Gherald
Veteran
Veteran
User avatar
Posts: 1399
Joined: Mon Aug 23, 2004 10:19 pm
Location: CLUAConsole

  • Quote

Post by Gherald » Sat Jan 15, 2005 7:57 pm

$> echo $(echo hi)
hi

$> echo `echo hi`
hi

and you can nest them:

$> echo $(echo $(echo hi))
hi

whereas this means something completely different:

$> echo `echo `echo hi``
US.EF.UL | mine | Stage 1/3 | console login | use cd -
Top
cfaun
n00b
n00b
Posts: 63
Joined: Sat Dec 25, 2004 2:40 pm

  • Quote

Post by cfaun » Sat Jan 15, 2005 10:35 pm

Yes, that is perfectly valid for bash programming, but in C/++ quotes are required, unless you want to write a very obscure program using ASCII character codes. In addition, writing often requires quotes.

But if neither of those two things apply to you, or if you use quotes infrequently, then Ox-'s approach is perfectly valid. Whatever works for you.
This sig intentionally left blank
Top
Gherald
Veteran
Veteran
User avatar
Posts: 1399
Joined: Mon Aug 23, 2004 10:19 pm
Location: CLUAConsole

  • Quote

Post by Gherald » Sat Jan 15, 2005 11:04 pm

cfaun wrote:to get ñ, what is easier, ALT+6549546194897461564987964242423, or windows-key+n?
I ignored this at first since it is obviously misguided, but I figure I should take the time to respond:

Windows uses ANSI, a superset of the ISO_8859-1 extended ASCII standard, and makes it easily acessible from all keyboards (Alt+164 for ñ, etc). Why doesn't X/Linux do the same?
US.EF.UL | mine | Stage 1/3 | console login | use cd -
Top
cfaun
n00b
n00b
Posts: 63
Joined: Sat Dec 25, 2004 2:40 pm

  • Quote

Post by cfaun » Sat Jan 15, 2005 11:30 pm

I am unaware why it doesn't do the same. To the best of my knownledge however, it doesn't. A more applicable question would be why should it do the same? Windows and GNU/Linux are different operating systems - they do somethings similarly and some things differently.
This sig intentionally left blank
Top
Gherald
Veteran
Veteran
User avatar
Posts: 1399
Joined: Mon Aug 23, 2004 10:19 pm
Location: CLUAConsole

  • Quote

Post by Gherald » Sat Jan 15, 2005 11:50 pm

The answer to why X/Linux should is obvious: the Windows approach is clearly superior in that it is more feature complete and easier to use in that you can type any extended ASCII character on any Windows system without any special configuration.
US.EF.UL | mine | Stage 1/3 | console login | use cd -
Top
cfaun
n00b
n00b
Posts: 63
Joined: Sat Dec 25, 2004 2:40 pm

  • Quote

Post by cfaun » Sun Jan 16, 2005 1:07 am

I do not disagree with you that it should. I just do no believe that it does.
This sig intentionally left blank
Top
dberkholz
Retired Dev
Retired Dev
User avatar
Posts: 1008
Joined: Tue Mar 18, 2003 6:51 am
Location: Minneapolis, MN, USA
Contact:
Contact dberkholz
Website

  • Quote

Post by dberkholz » Thu Feb 03, 2005 5:50 am

freeix wrote:
cfaun wrote:to get �, what is easier, ALT+6549546194897461564987964242423, or windows-key+n?
I ignored this at first since it is obviously misguided, but I figure I should take the time to respond:

Windows uses ANSI, a superset of the ISO_8859-1 extended ASCII standard, and makes it easily acessible from all keyboards (Alt+164 for �, etc). Why doesn't X/Linux do the same?
Actually, you can easily use UTF-8 instead, which I use. It's superior to ISO8859-1. You can read a little bit about why here or here.

In my xorg.conf, I have Option "XkbLayout" "en_US". Also, I set LANG and LC_ALL in my .bashrc, as the first above link suggests.
Top
Gherald
Veteran
Veteran
User avatar
Posts: 1399
Joined: Mon Aug 23, 2004 10:19 pm
Location: CLUAConsole

  • Quote

Post by Gherald » Thu Feb 03, 2005 6:02 am

Yes you can use UTF-8... that doesn't concern me.

I just want working Alt+### codes.
US.EF.UL | mine | Stage 1/3 | console login | use cd -
Top
dberkholz
Retired Dev
Retired Dev
User avatar
Posts: 1008
Joined: Tue Mar 18, 2003 6:51 am
Location: Minneapolis, MN, USA
Contact:
Contact dberkholz
Website

  • Quote

Post by dberkholz » Thu Feb 03, 2005 6:30 am

freeix wrote:Yes you can use UTF-8... that doesn't concern me.

I just want working Alt+### codes.
Try Ctrl+Shift+####. Works in gnome.
Top
cfaun
n00b
n00b
Posts: 63
Joined: Sat Dec 25, 2004 2:40 pm

  • Quote

Post by cfaun » Thu Feb 03, 2005 11:05 pm

Works in KDE too.
This sig intentionally left blank
Top
teilo
Apprentice
Apprentice
User avatar
Posts: 276
Joined: Fri Jun 20, 2003 2:36 pm
Location: Minneapolis, MN

  • Quote

Post by teilo » Sat Feb 05, 2005 6:36 pm

spyderous wrote:
freeix wrote:Yes you can use UTF-8... that doesn't concern me.

I just want working Alt+### codes.
Try Ctrl+Shift+####. Works in gnome.
The support for Ctrl+Shift+#### is in a state of flux and seems to have more to do with the widgets used, than the wm. For me, at least, it works in gtk2 apps (gvim, gedit, Firefox, Thunderbird, Evolution, the latest OpenOffice.org developer builds) but not in any gtk1, Qt (including KDE) apps, or in the stable OpenOffice.org builds.

Typing Unicode keystrokes in Hex is much more troublesome than the Windows Alt trick, but at least it's available. For the characters I use commonly (ndash, mdash, elipses, bullets, and various ligatures), I find the xmodmap trick much more versatile.
Teilo who is called Teilo
Top
vdboor
Guru
Guru
User avatar
Posts: 592
Joined: Wed Dec 03, 2003 9:31 am
Location: The Netherlands
Contact:
Contact vdboor
Website

  • Quote

Post by vdboor » Sun Feb 06, 2005 12:15 pm

I've had some problems for this too, but learned the following:

To write ß, hit compose+s+s
To write æ, hit compose+a+e
To write é, hit compose+'+e

The compose key can be defined with XModMap, or use this line in xorg.conf:

Code: Select all

Option "XkbOptions"   "compose:rwin"
Place it in the keyboard section off course ;)


The Euro sign should appear with compose+=+e, but this only works in Gtk applications for me. It doesn't work with KDE/Qt applications, perhaps this is caused by the encoding Qt uses for it's strings. (utf8)

freeix wrote:The answer to why X/Linux should is obvious: the Windows approach is clearly superior in that it is more feature complete and easier to use in that you can type any extended ASCII character on any Windows system without any special configuration.
:roll: remembering an ASCII code is superior then Compose+SS..? :-P

However, I agree on one part: the windows version doesn't require any configuration. It's a shame Linux doesn't have a easy way, and a lot of applications are not euro-ready. (ever tried to display an euro sign at an xterm?) I was hoping someone in this thread could help me out.
The best way to accelerate a windows server is by 9.81M/S²
Linux user #311670 and Yet Another Perl Programmer

[ screenies | Coding on KMess ]
Top
tom56
Guru
Guru
User avatar
Posts: 325
Joined: Tue Apr 27, 2004 8:39 pm
Location: united kingdom

  • Quote

Post by tom56 » Mon Feb 07, 2005 9:29 am

Here the "alt gr" key does all this by default.

For example:
alt gr + s = ß
alt gr + [ then o = ö
alt gr + 3 = €

Much easier than any of the ways described here. I especially like it because it is consistent. Pressing alt gr and [ followed by a vowel gives that vowel an umlaut (¨). Pressing alt gr and ] followed by a letter will give that letter a wavy accent (~, like ñ).

Tom.
"A million surplus Maggies are willing to bear the yoke; And a woman is only a woman, but a good cigar is a Smoke" -- Rudyard Kipling (on why he chose cigars over his wife)
Top
davecs
Guru
Guru
User avatar
Posts: 436
Joined: Sat Nov 08, 2003 3:34 pm
Location: Dagenham, GB

  • Quote

Post by davecs » Mon Feb 07, 2005 12:44 pm

I'm at work at present on the Windoze computer, so I may make odd errors here.

Firstly, if you allow dead keys in your basic keyboard setup, and you support the Right-Alt key as a third level chooser (this seems to be Standard in Gentoo with a GB keyboard) you get alternate keys by pressing Right-Alt + a key (and Shift-Right-Alt). The file that defines this is called "latin" it's under /etc/X11/...../pc/ somewhere (as I say I'm not on my own computer at the moment) and can be edited if you are not happy with the standard choices, though you should both back up and save your alternative elsewhere as any upgrade of xorg-x11 will overwrite it. As standard, ALT-GR + the three symbol keys right of letter L appear dead, but cause accents to appear on certain letters. Depending on your locale, ALT-GR with =, [, ], / do similar things, and SHIFT-ALT-GR also produce others.

Other normal behaviour is that the Windows "Menu" key acts in Linux as a Compose key though an alternate can be defined if you don't have one. Press Menu, o, e for the oe ligature, or Menu, O, / for Oslash.

There is also a key that enables you to input the four Hex digit unicode number though I rarely have to resort to it so I can't remember which it is.

And Windows let's you enter 127 characters not on the keyboard, using ALT. Is that all? Hah!!
Gentoo, PCLOS-pre-81a and Windows 98SE.
Shuttle SN41G2V2
Athlon XP2500+ o/c to 3200+, 2x256Mb Geil Value RAM, FX5200.
Ntlworld cable internet via ethernet
and PC-Chips Desknote Laptop (with PCLOS-pre-81a )
Top
vdboor
Guru
Guru
User avatar
Posts: 592
Joined: Wed Dec 03, 2003 9:31 am
Location: The Netherlands
Contact:
Contact vdboor
Website

  • Quote

Post by vdboor » Mon Feb 07, 2005 9:44 pm

tom56 wrote:For example:
alt gr + s = ß
alt gr + [ then o = ö
alt gr + 3 = €
I'm curous; the compose + [ trick doesn't work for me.. Any ideas what causes this?

This is my keyboard section:

Code: Select all

Section "InputDevice"
    Identifier            "LogitechDC_Keyboard"
    Driver                "kbd"  # "Keyboard"

    Option "AutoRepeat"   "500 30"

    Option "XkbModel"     "logicdp"  # logitech cordless desktop pro ("desktop comfort")
    Option "XkbOptions"   "compose:rwin"
    Option "XkbLayout"    "us"       # us, en_US, nl(euro)

### Option "XkbVariant"   "intl"     # international keys (typing 'e displays é)
EndSection
The best way to accelerate a windows server is by 9.81M/S²
Linux user #311670 and Yet Another Perl Programmer

[ screenies | Coding on KMess ]
Top
davecs
Guru
Guru
User avatar
Posts: 436
Joined: Sat Nov 08, 2003 3:34 pm
Location: Dagenham, GB

  • Quote

Post by davecs » Tue Feb 08, 2005 11:30 am

vdboor wrote:I'm curous; the compose + [ trick doesn't work for me.. Any ideas what causes this?
It's not compose you want, it's Third Level Chooser. Which is normally the right alt (ALT-GR) key. You have defined it to do something else.

Normally, ALTGR-; then e causes e-grave. As you have ALTGR redefined as Compose, you have to do

ALTGR, then reverse apostrophe, then e.

If you have a Windows Menu key, that should be your compose key.
Gentoo, PCLOS-pre-81a and Windows 98SE.
Shuttle SN41G2V2
Athlon XP2500+ o/c to 3200+, 2x256Mb Geil Value RAM, FX5200.
Ntlworld cable internet via ethernet
and PC-Chips Desknote Laptop (with PCLOS-pre-81a )
Top
grant.mcdorman
Apprentice
Apprentice
User avatar
Posts: 295
Joined: Wed Jan 29, 2003 2:01 am
Location: Toronto, ON, Canada

Re: Easy accents in X11

  • Quote

Post by grant.mcdorman » Wed Feb 09, 2005 1:45 am

cfaun wrote:

Code: Select all

#!/usr/bin/bash
xmodmap -e 'keycode 115 = Mode_switch'
I'd recommend you don't use keycodes. While this will work wonderfully for your current keyboard, something as simple as switching keyboards will get you into trouble, since keycode 115 won't be the same physical key anymore. It may even happen when upgrading your X server, or switching to a different server. It is practically guaranteed to happen with virtual displays (VNC and probably NX).

Instead, look at the xev output, and use the the keysym; e.g.

Code: Select all

KeyRelease event, serial 30, synthetic NO, window 0x3a00001,
    root 0x48, subw 0x3a00002, time 8690836, (34,55), root:(1110,77),
    state 0x0, keycode 90 (keysym 0xff9e, KP_Insert), same_screen YES,
    XLookupString gives 0 bytes:
Here, the keysym is KP_Insert, so your xmodmap command would be:

Code: Select all

keysym KP_Insert = Mode_switch
This means that 1) it will work no matter what happens to your keyboard and 2) it won't break things if that key isn't there.

The only time to use the keycode is when the key has, by default, no keysym assigned; this is often the case for those special media keys.

Incidentally, on the original topic: I prefer the compose-sequences myself. All of the extended Latin-1 (ISO8859-1) characters can be entered this way, plus some base ASCII characters. It does not include the non-printable characters, which is the only advantage the Windows ALT+NumPad method has. The complete list is in /usr/lib/X11/locale/iso8859-1/Compose; note that there are other compose maps for other locales. (Most characters have at least two alternative sequences; many have four or more).

The compose sequences are very old (in computer terms); I remember having them on Sun systems ten years ago.

I had at one time a program that would provide compose sequences on Windows: you pressed and released the Ctrl key, and then pressed the other two keys to get the extended character. Worked fairly well; however, I don't have the program around any more, and I don't have any need for it in Windows.
Top
Post Reply

34 posts
  • 1
  • 2
  • Next

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic