10

I recently switched to Ubuntu on my laptop and one thing that almost got me to switch back to windows is the fact that I can't make Ctrl + Alt to act like Alt gr.

I have programmed in several years and for example I'm so used to make the sign "$" by pressing ctrl + alt + 4. Here in Ubuntu I have to use "Alt gr + 4" witch almost makes me insane...

Is there a fix for this?

  • 1
    have you tried playing with the mappings of the composekey? help.ubuntu.com/community/ComposeKey – Tim Kennedy Jul 28 '13 at 12:52
  • You can use xmodmap command to do this. Check this askubuntu.com/questions/5095/typing-using-key-combinations – Bichoy Jul 29 '13 at 0:35
  • Try xmodmap, which is available in the x11-xserver-utils package in ubuntu. It allows you to remap any key combination. – Warren Nov 12 '13 at 15:27
  • @elitasson If you find out the answer to your own question, please psot it as a separate answer. – Bernhard Dec 30 '13 at 9:16
  • @Bernhard No, you can't do this with xmodmap. It doesn't support making the Ctrl+Alt combination a distinct modifier. But I think you can with xkb. – Gilles Sep 28 '16 at 22:47
3

You could add global shortcuts to write special chars. I use this often for my German keyboard layout with Ubuntu (on Windows this work out of the box).

I added the following shortcuts:

Shift+Enter+7 to write the letter {

Shift+Enter+0 to write the letter }

Shift+Enter+8 to write the letter [

Shift+Enter+9 to write the letter ]

To add these shortcuts you will need xbindkeys and xvkbd:

sudo apt-get install xbindkeys xvkbd

Then edit the configuration file:

vim ~/.xbindkeysrc

And add the following lines (edit them as you prefer):

"xvkbd -xsendevent -text '{'"
    m:0xc + c:16
    Control+Alt + 7

"xvkbd -xsendevent -text '['"
    m:0xc + c:17
    Control+Alt + 8

"xvkbd -xsendevent -text ']'"
    m:0xc + c:18
    Control+Alt + 9

"xvkbd -xsendevent -text '}'"
    m:0xc + c:19
    Control+Alt + 0

"xvkbd -xsendevent -text '\[backslash]'"
    m:0xc + c:20
    Control+Alt + ssharp

"xvkbd -xsendevent -text '\[asciitilde]'"
    m:0xc + c:35
    Control+Alt + plus

Then reload xbindkeys:

xbindkeys -f ~/.xbindkeysrc

Thanks to whizz for sharing this (http://forum.ubuntuusers.de/topic/strg-%2B-alt-alt-gr-wie-in-windows/).

  • 1
    Could you explain what the lines m:0xc + c:XX does? – elitasson Mar 25 '15 at 9:31
  • 1
    I know this is an old question and answer, but just for those who want to add more characters like | or @ or €: The key codes used at c:XX are, as far as I know, not universal, so you won't have luck googling that. You can however find out a key code locally by installing and executing "xev" in your command line. It will print all of your keyboard and mouse actions, so you'll have to scroll a bit to find "your" character. – Nano Miratus Jan 12 '18 at 9:18
  • 1
    For example, pressing < (to configure |) while running xev prints this out: KeyRelease event, serial 40, synthetic NO, window 0x4c00001, root 0x7e, subw 0x0, time 35363548, (135,60), root:(903,472), state 0x0, keycode 94 (keysym 0x3c, less), same_screen YES, XLookupString gives 1 bytes: (3c) "<" XFilterEvent returns: False The number you need is always in the third line, after "keycode". So in this case, 94. – Nano Miratus Jan 12 '18 at 9:23
2

After trying and failing to get it to work with a combination of xbindkeys and xvkbd/xte (I could never get certain characters {, [, ], }, \, etc. to behave properly perhaps because I use a Scandinavian keyboard layout), I finally found a simple and practical solution: Autokey. Here are the exact instructions to get it working:

  1. Install Autokey through Ubuntu Software (I used the GTK-version, not KDE) or by: “sudo apt-get install autokey-gtk”.
  2. Configure one script per key, e.g. for { use this code: keyboard.send_keys("<alt_gr>+7") and set the hotkey to Ctrl+Alt+7 (first set hotkey to 7 then add Ctrl and Alt as modifiers). This at least worked for the most important code-writing keys: { [ ] } .
  3. Add autokey to Startup Applications (search for “start” to find it) and then add a program with “autokey” as the command.

This solution will work for anything running in the current X-session (I think) but will not work if you start a new terminal session using Ctrl+Alt+(F2-F6).

1

Although this still doesn't answer your question, I find this to be an easier solution than the other answers.

To make R-ALT work like AltGr, you can add the following line to your ~/.xinitrc:

setxkbmap -option lv3:ralt_switch

Other ways to shift to the 3rd level (that which is usually achieved using AltGr key) can found, and new ways can be defined in /usr/share/X11/xkb/symbols/level3.

1

Here is what I did to make the L-Alt key act exactly the same as the Altgr key. I didn't try with the CtrlAlt key

It consists in modifying the level3 file

In the terminal, change directory :

cd /usr/share/X11/xkb/symbols

make a copy of the level3 file :

sudo cp level3 level3.old

edit level3 with any text editor :

sudo gedit level3 

You should find a block like this :

  key <RALT> {
    type[Group1]="ONE_LEVEL",
    symbols[Group1] = [ ISO_Level3_Shift ]
    };
  modifier_map Mod5   { ISO_Level3_Shift };

Add a copy of the block with LALT (left alt) instead of RALT (altgr) :

  key <LALT> {
    type[Group1]="ONE_LEVEL",
    symbols[Group1] = [ ISO_Level3_Shift ]
    };
  modifier_map Mod5   { ISO_Level3_Shift };

Now, there should be 3 other blocks starting with key <RALT>

Do the same with them.

Save and quit.

0

I only use the special signs when I write code so I managed to fix this is Sublime Text.

In Preferences -> Key bindings - User

insert the following:

[
{ "keys": ["ctrl+alt+2"], "command": "insert", "args": {"characters": "@"} },
{ "keys": ["ctrl+alt+3"], "command": "insert", "args": {"characters": "£"} },
{ "keys": ["ctrl+alt+4"], "command": "insert", "args": {"characters": "$"} },
{ "keys": ["ctrl+alt+5"], "command": "insert", "args": {"characters": "€"} },
{ "keys": ["ctrl+alt+7"], "command": "insert", "args": {"characters": "{"} },
{ "keys": ["ctrl+alt+8"], "command": "insert", "args": {"characters": "["} },
{ "keys": ["ctrl+alt+9"], "command": "insert", "args": {"characters": "]"} },
{ "keys": ["ctrl+alt+0"], "command": "insert", "args": {"characters": "}"} },
{ "keys": ["ctrl+alt++"], "command": "insert", "args": {"characters": "\\"} },
{ "keys": ["ctrl+alt+<"], "command": "insert", "args": {"characters": "|"} }

]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.