4

I have just recently moved from MS windows to Linux, and it is great; but there is one thing that really bugs me, and that is the use of Ctrl+Alt+key instead of using Alt Gr+key.

When I program, it irritates me that often used buttons like curly-braces and square-brackets are not easily accessed through Ctrl+Alt+key. How do I change the behavior of Ctrl+Alt+key to do the same as Alt Gr+key?

As mentioned earlier, my keyboard has a Danish layout.

1
  • I am also used to type "{" via Ctrl + Alt + Key with Key being on my keyboard layout the "7" (offering "/" and "{"). For AltGr + Key I would have to lift my left hand which is way too much effort to right bracket-prone code in R f.x. It seems this question is specific to non-US-layouts.
    – Raffael
    Feb 18, 2014 at 14:31

4 Answers 4

5
+50

You can try xbindkeys

sudo apt-get install xbindkeys

Create the default config file for xbindkeys

xbindkeys --defaults > /home/your-user-name/.xbindkeysrc

Install xbindkeys-config, the GUI for xbindkeys

sudo apt-get install xbindkeys-config
sudo apt-get install xvkbd

Start xbindkeys with Ctrl+F2

xbindkeys

For GUI editor:

xbindkeys-config

Edit the file ~/.xbindkeysrc

Comment commands there that you don't want.

At the end of the file, put the mapping that you want:

Example: Launch Firefox with Ctrl+F

Firefox: Ctrl+F

The first line is the command line operation to send when your desired key combination occurs.

The second line is the keystroke to invoke the operation

To find the syntax for the AltGr key being pressed, you can run the xbindkeys-config utility and click the Get Key button.

Then

""xvkbd -xsendevent -text '[AltGr]'"" Ctrl+Alt

Final note: you can set xbindkeys to launch on startup — in Ubuntu, just go to System -> Preferences -> Startup Applications and add a new command xbindkeys.

Also check this article from our website

Source of article

6
  • cannot make it work using the xbindkeys-config GUI editor for Ctrl-F to open Firefox. xbindkeys -s shows the new command but XTerminal keeps on opening.
    – Raffael
    Feb 18, 2014 at 21:52
  • See the file ~/.xbindkeysrc comment out everything that you don't want. Firefox was just an example
    – LnxSlck
    Feb 19, 2014 at 11:33
  • I did what you said, though with some minor moderations - I made it like this: "xvkbd -xsendevent -text '\{'" Ctrl + Alt + 7 It works fine in Mozilla firefox, Libre Writer, Dash Home, etc. But in some programs, including software center and especially the terminal it does not work. I use the terminal a lot, so is irritating me a lot. Any suggestions on why it is acting like this? Feb 26, 2014 at 22:19
  • Maybe the terminal already has shortcut keys assigned ?
    – LnxSlck
    Feb 27, 2014 at 11:15
  • @LnxSlck If that is the case, how do I change them? Do you know if there is a better binding than Ctrl + Alt? Perhaps Shift + Alt? Mar 3, 2014 at 20:25
3

Keyboard > Shortcuts > Typing > Alternative Character Keys:

Select f.x. Left Alt

The caveat is that this solution will disable a all OS and GUI shortcuts where Alt is involved ... not good.

But it seems to make perfect sense to use Caps Lock.

Only CHOLERICS need it and it is actually easier to type than Alt or Ctrl+Alt.


On Linux Mint 17.3 there is no option for mapping Caps Lock to AltGr. But I found this solution to work:

https://superuser.com/a/533073/163236

0
2

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/).

This is a copy of my answer on unix.stackexchange.com: https://unix.stackexchange.com/a/184886/103140

0

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).

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .