Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Easy accents in X11
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
cfaun
n00b
n00b


Joined: 25 Dec 2004
Posts: 63

PostPosted: Sat Jan 15, 2005 12:31 am    Post subject: Easy accents in X11 Reply with quote

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:

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:

#!/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:

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:

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:

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
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Sat Jan 15, 2005 2:05 am    Post subject: Reply with quote

Is there no possible way to get it to behave exactly as Alt+numpadkeys does on Windows?
Back to top
View user's profile Send private message
cfaun
n00b
n00b


Joined: 25 Dec 2004
Posts: 63

PostPosted: Sat Jan 15, 2005 2:21 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Sat Jan 15, 2005 2:52 am    Post subject: Reply with quote

On my keyboard it would have to be the former, seeing as I don't have a windows key : )
Back to top
View user's profile Send private message
Ox-
Guru
Guru


Joined: 19 Jun 2003
Posts: 305

PostPosted: Sat Jan 15, 2005 3:23 am    Post subject: Reply with quote

I just use put:
Code:
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.
Back to top
View user's profile Send private message
cfaun
n00b
n00b


Joined: 25 Dec 2004
Posts: 63

PostPosted: Sat Jan 15, 2005 3:15 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Sat Jan 15, 2005 6:53 pm    Post subject: Reply with quote

Are you aware of $( ) in bash? It's easier to read, and nestable.
Back to top
View user's profile Send private message
cfaun
n00b
n00b


Joined: 25 Dec 2004
Posts: 63

PostPosted: Sat Jan 15, 2005 7:38 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Sat Jan 15, 2005 7:57 pm    Post subject: Reply with quote

$> 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``
Back to top
View user's profile Send private message
cfaun
n00b
n00b


Joined: 25 Dec 2004
Posts: 63

PostPosted: Sat Jan 15, 2005 10:35 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Sat Jan 15, 2005 11:04 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
cfaun
n00b
n00b


Joined: 25 Dec 2004
Posts: 63

PostPosted: Sat Jan 15, 2005 11:30 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Sat Jan 15, 2005 11:50 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
cfaun
n00b
n00b


Joined: 25 Dec 2004
Posts: 63

PostPosted: Sun Jan 16, 2005 1:07 am    Post subject: Reply with quote

I do not disagree with you that it should. I just do no believe that it does.
_________________
This sig intentionally left blank
Back to top
View user's profile Send private message
dberkholz
Retired Dev
Retired Dev


Joined: 18 Mar 2003
Posts: 1008
Location: Minneapolis, MN, USA

PostPosted: Thu Feb 03, 2005 5:50 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Thu Feb 03, 2005 6:02 am    Post subject: Reply with quote

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

I just want working Alt+### codes.
Back to top
View user's profile Send private message
dberkholz
Retired Dev
Retired Dev


Joined: 18 Mar 2003
Posts: 1008
Location: Minneapolis, MN, USA

PostPosted: Thu Feb 03, 2005 6:30 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
cfaun
n00b
n00b


Joined: 25 Dec 2004
Posts: 63

PostPosted: Thu Feb 03, 2005 11:05 pm    Post subject: Reply with quote

Works in KDE too.
_________________
This sig intentionally left blank
Back to top
View user's profile Send private message
teilo
Apprentice
Apprentice


Joined: 20 Jun 2003
Posts: 276
Location: Minneapolis, MN

PostPosted: Sat Feb 05, 2005 6:36 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
vdboor
Guru
Guru


Joined: 03 Dec 2003
Posts: 592
Location: The Netherlands

PostPosted: Sun Feb 06, 2005 12:15 pm    Post subject: Reply with quote

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:
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 ]
Back to top
View user's profile Send private message
tom56
Guru
Guru


Joined: 27 Apr 2004
Posts: 325
Location: united kingdom

PostPosted: Mon Feb 07, 2005 9:29 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
davecs
Guru
Guru


Joined: 08 Nov 2003
Posts: 436
Location: Dagenham, GB

PostPosted: Mon Feb 07, 2005 12:44 pm    Post subject: Reply with quote

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 )
Back to top
View user's profile Send private message
vdboor
Guru
Guru


Joined: 03 Dec 2003
Posts: 592
Location: The Netherlands

PostPosted: Mon Feb 07, 2005 9:44 pm    Post subject: Reply with quote

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:
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 ]
Back to top
View user's profile Send private message
davecs
Guru
Guru


Joined: 08 Nov 2003
Posts: 436
Location: Dagenham, GB

PostPosted: Tue Feb 08, 2005 11:30 am    Post subject: Reply with quote

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 )
Back to top
View user's profile Send private message
grant.mcdorman
Apprentice
Apprentice


Joined: 29 Jan 2003
Posts: 295
Location: Toronto, ON, Canada

PostPosted: Wed Feb 09, 2005 1:45 am    Post subject: Re: Easy accents in X11 Reply with quote

cfaun wrote:
Code:

#!/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:
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:
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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum