I switch back and forth between two computers constantly:

  • OSX Snow Leopard
  • Ubuntu 10.10

I'd like to be able to make Ubuntu use the same keyboard shortcuts as OSX System Wide, for the following keyboard sequences only (ie I don't want to make Ctrl act like Super)

  • Super+C -> Copy

  • Super+V -> Paste

  • Super+T -> Open a new tab in whatever browser I'm in.

  • Super+W -> Close a tab in whatever browser I'm in.

So in short, is there anyway for me to map just these keyboard sequences to the following, system wide ?

  • Super+C -> Ctrl+C
  • Super+V -> Ctrl+V
  • Super+T -> Ctrl+T
  • Super+W -> Ctrl+W

I know there are ways for me to do this for vim, and Firefox, and I'm sure specifically for most applications... but I would prefer to have to do this just once and have it work that way system wide!

I'm using a standard PC keyboard, that is "Generic 105 key (intl) PC" on Ubuntu. I'm also using the same keyboard on my Mac mini.

  • 1
    If you got this dialed in for all the Mac keyboard shortcuts, sharing your config file would be terrific! Thanks – Dolan Antenucci Apr 19 '13 at 16:58
  • hey! I wish I still did, but I'm working exclusively on Mac's now, as I've moved jobs ;-) So I don't have my old config around anywhere... – brad parks Apr 19 '13 at 17:13
  • solutions do not work on elementary OS.' – Paschalis Sep 3 '16 at 10:02
up vote 29 down vote accepted

If you install the xautomation package, you can add a command in System/Preferences/Keyboard Shortcuts/Custom like:

xte "keyup Meta_L" "keyup c" "keydown Control_L" "key c" "keyup Control_L"

and map that to Meta-C.


Alternative Solution:

Install AutoKey (apt-get install autokey-gtk) and set a phrase to:

Phrase Text: <ctrl>+C (actually type out the <ctrl>+ here)
Paste Using: Keyboard
Abbreviation: None
Hotkey: <super>+v
Window Filter: None
  • hey! this looks very promising... i've installed, and can run the above xte command from the terminal, and it outputs "^C" in the terminal... which looks good to me! but when i map it in Keyboard Shortcuts, it doesn't do anything... I tried mapping another program to Meta-C, and it works fine (ie launches fine when I press Meta-C). I also tried specifying the full path to xte (/usr/bin/xte) and that didn't work either... can you try this on your system and see if it works? thanks! – brad parks Nov 6 '10 at 1:18
  • 1
    So xte sends the key codes correctly, but apparently applications see the combination of the shortcut and the keypresses sent by xte (e.g. Meta-Control-C). I've updated my answer to simulate releasing the shortcut keys before sending the key presses. – cscarney Nov 6 '10 at 5:18
  • doesn't work for me even with keyup – hasen Nov 6 '10 at 6:54
  • 2
    On quick check it works for me, but I've found a solution that will probably be more reliable than xte (even if you get it working). Check the revised answer. – cscarney Nov 6 '10 at 14:09
  • 1
    hey! thanks @cscarney! your "Alternative Solution" for AutoKey totally works! thanks a ton for your continued effort on this! – brad parks Nov 8 '10 at 17:29

For Ubuntu 14 or newer you can do this:

sudo apt-get install gnome-tweak-tool

Than, look for Tweak Tool > Typing > Alt/Win key behavior

And check: Ctrl is mapped to Win keys (and usual Ctrl keys)

  • Does not seem to do anything or is not Mac behavior – chovy Dec 3 '16 at 4:29
  • In a fresh install of Ubuntu 16, installing this seems to require gnome-settings-daemon which seems to lead down a trail of packages that don't feel like they were meant to be installed. – Tom Lianza Feb 5 '17 at 15:37
  • By far the most straight forward option if you just want the command key to be like the cmd key in mac, mainly for copy and paste. I'm on ubuntu-gnome-desktop – lxm7 Mar 20 '17 at 23:18
  • This works great for copy-paste commands and keeps me from constantly opening the search menu thing in Ubuntu. Now I just need to map Command-Tab to Alt-Tab – Ron Smith Jul 9 '17 at 2:13
  • This works for me! – lkahtz Oct 19 '17 at 4:23

There is a way to map Ctrl to Win/Super key:

  1. go to system->preferences->keyboard,

  2. open tab Layouts,

  3. click Options...,

  4. open Alt/Win key behavior,

  5. and select Control is mapped to Win keys

And for console there is a forum post how to do that here.

For more digging check general Linux keyboard HOWTO here.

regards

  • 2
    hey @danizmax - thanks for the reply... but I'd specifically like to avoid changing the complete behaviour of Ctrl... I find it screws with other things if I do... I'd really like to map just the keyboard shortcuts that I mentioned in the post... thanks though! – brad parks Nov 4 '10 at 0:00
  • Well the Ctr+ stays as it is. It only duplicates all Ctrl+ to Super+ so you just add the behavior. Unless you really really wanna change only those you mentioned, you'll have to do a lot of digging with xmodmap and loadkeys. I've added the link to the general Linux keyboard HOWTO. Hope it helps :P – danizmax Nov 4 '10 at 11:40
  • 1
    This was the easiest solution from all proposed. – Datageek Mar 16 '13 at 16:21
  • 1
    I don't see the "options" or "alt/win key behavior" option in the system settings any more in Ubuntu 15.10 wily. – user29020 Mar 5 '16 at 2:07
  • I don't see "layouts" either. – chovy Dec 3 '16 at 4:21

To expand on cscarney's AutoKey hint, I am developing my AutoKey configuration to achieve all this in Ubuntu (OS X-like <cmd>+c, <cmd>+v, ... Emacs-style <ctrl>+f, <ctrl>+b, ...) in my dotfile repo.

I don't use basic phrases (where window filtering is currently broken), but Python scripts, to be able to disable AutoKey in apps such as Emacs, Eclipse, Vim, gnome-terminal ... where I don't want to mess up the existing shortcuts.

You can check out the README on the bottom for instructions on how to set it up.

This is an easy task once you know how to do it.

1) Check the keycode of yours key. Run this program at terminal.

xev


At this example, the terminal shows that the keycode for my k is "45".

2) Change them as you like creating this file:

gedit ~/.Xmodmap

It's contents should look like this example:

keycode 64 = Alt_L Meta_L Alt_L Meta_L
keycode 108 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift

(Change the keycode number as needed - look at step "1")

Ilustration:
(Obs.: if I want to change my k I should use "keycode 45" as showed at step "1").

4) Logout and log back in or reboot or run this:

xmodmap ~/.Xmodmap

Hope you enjoy ;-)

First
Install Guest Additions CD (Devices->Insert Guest Additions CD image).

Activate clipboard sharing
Then after a reboot, in Virtualbox go to Machine->Settings->General->Advanced and set
Shared Clipboard: Bidrectional

Change VirtualBox Host Key
In Vitualbox/Preferences/Input/Virtual Machine/Host Key Combination
choose sth different then

Key Mapping:
For the cmd/ctrl mapping for me adding the English (Macintosh) keyboard seems to be the most comfortable solution :)

Go to Ubuntu Settings->Text Entry
(I guess in older versions it might be in Keyboard Layout Settings)
Under Input sources to use: hit plus (+)
add English (Macintosh)

I'm on Ubuntu 14.04.3 LTS 64bit in VirtualBox 5.0.4

I don't have Ubuntu to hand (Mac's here, Ubu's at the office) but I use a Mac keyboard there and for the same reasons as you, wanted to do this.

First thing is to make sure your keyboard was installed as a Mac keyboard. I think you can change this in system->preferences->keyboard. While you're there one of the tabs will get you to a key mapping page where you can set up how the cmd key works.

Like I say, I can't remember exactly - I can point to the bits on my screen here, but that doessn't work because I'm not there.

If you're still stuck tomorrow, I'll look again.

  • system->preferences->keyboard->layouts->options – Leo Oct 29 '10 at 8:27
  • hi leo... i'm not using a Mac keyboard with Ubuntu though... I'm using a standard PC keyboard, ie "Generic 105 key (intl) PC" did try switching my "keyboard model" to Vendor Apple / Model Apple but that didn't seem to make any difference.... I also tried Vendor Apple / Model Macbook and that didn't seem to change anything either... – brad parks Oct 29 '10 at 12:11
  • and for what it's worth, I use the exact same PC keyboard on my macmini as well, as I bought it second hand and it didn't come with a mac keyboard. thanks again. – brad parks Oct 29 '10 at 12:17

Autokeys did work for me. Now win+c (v,x,a) work around my system just like I'd expect it.

1. Install autokeys

sudo apt install autokey-gtk

2. Configure autokeys

  1. Add root folder, call it something like MacKeys or whatever
  2. You'll create 4 scripts in there for ctrl-c, v,x and a
  3. assign to each script hotkey super-c, super-v etc
  4. fill the scripts with code below (replace letter c for other combos)

winClass = window.get_active_class() keys = "<ctrl>+c" if winClass == "gnome-terminal-server.Gnome-terminal": keys = "<ctrl>+<shift>+c"; keyboard.send_keys(keys)

4a. For CmdZ, CmdA or CmdX work with simpler script like keyboard.send_keys("<ctrl>+x")

3. Add /usr/bin/autokey-gtk to startup applications

4. Disable win-A in keyboard settings

Normally win-a makes switch to overview.

5. Optional, fully prevent win to switch the overview

Probably you will want to remove it. Install gnome-tweak-tool, go to keyboard and rebind switching from desktop to overview. That worked for my gnome ubuntu 16.04.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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