How to Right Click Using the Keyboard from Ubuntu on a Mac

I'm running Ubuntu on a Macbook Pro. How do you right-click using the keyboard in this setup? I've read that holding down the command key simulates pressing the "context menu" button on a Windows machine, but this behavior doesn't seem to be present in Ubuntu. I also don't see any way to configure this in Ubuntu's keyboard shortcut preferences dialog. Is there anyway else to do it?

Following JJ Stiff's answer, I tried installing xbindkeys and adding to my ~/.xbindkeysrc:

"sleep .05 && xdotool click 3"
  m:0x50 + c:134

Running xbindkeys -k and pressing the right command key reported that the code for the right command key is m:0x50 + c:134, thus the entry above.

However, when running xbindkeys -v, pressing the right command key still has no effect.


Solution 1:

Shift + F10

I really want to but I don't know how to customize this. Perhaps with xbindkeys?

Solution 2:

Scroll down to Steps, to see the solution.

Okay. Got it. Here's a solution to make apple-click (command-click) work as right-click. I also include apple-shift-click to work as middle-click. And I have added shift-delete to act as del rather than as BackSpace. This solution requires xbindkeys and xdotool.

Running Ubuntu Desktop 13.10 on MacBookPro2,2. For those that forgot, the MacBook Pro only has one mouse button. While it is supporting two-finger scroll out-of-the-box, there does not appear to be any way to right-click on ubuntu (out-of-the-box) on a macbookpro (without an external mouse). Apparently option-(Fn-)F10 is one almost-workaround, but it is not quite the same.

Since the original post, these combinations were tried but are not quite acceptable:

  • control + b:1 - ctrl-click enables multiple selections in the file manager and elsewhere.
  • option + b:1 - option (alt) provides functions in ubuntu which inhibit option-click from working.
  • shift + b:1 - shift-click is also a problem due to file selection.
  • control + option + b:1 - ctrl-option-click Sometimes requires a double mouse click, possibly because of ubuntu's use of option (alt).

The current recommendation is for apple-click; it seems to work well even though apple (command) (also called Super) does bring up the Keyboard Shortcuts window:

  • Mod4 + b:1 - xdotool click 3
  • Mod4 + shift + b:1 - xdotool click 2
  • shift + BackSpace - xdotool key --clearmodifiers Delete #Note: does not auto-repeat.

Note: I have found the need to sleep before running xdotool from xbindkeys: .05 is okay for xdotool click but .10 is required for xdotool key. [I lowered it to .04 and .07, with success.] (May I have an explaination please? My assumption is that xbindkeys and the system need to finish handling the current event before xdotool can send a new event. Wow, shift-delete is so useful: how could you live without it on a mac? I just wish it didn't need to pause and could auto-repeat.)

References:

  1. http://dennisideler.com/blog/custom-key-bindings-in-linux/
  2. http://tuxradar.com/content/xdotool-script-your-mouse
  3. man xbindkeys
  4. man xdotool

Steps:

  1. sudo apt-get install xbindkeys
  2. sudo apt-get install xdotool
  3. (optional and not necessary) xbindkeys --defaults > ~/.xbindkeysrc && less ~/.xbindkeysrc to familiarize yourself with the xbindkeys notation. q to quit out of less. But this file contains a ctrl-f binding which inhibits regular searching, so I would remove it with rm ~/.xbindkeysrc before proceeding: or, at least, comment out the ctrl-f binding.

  4. create ~/.xbindkeysrc to contain the six lines:

    "sleep .04 && xdotool click 3"
      Mod4 + b:1
    
    "sleep .04 && xdotool click 2"
      Mod4 + shift + b:1
    
    "sleep .07 && xdotool key --clearmodifiers Delete"
      shift + BackSpace
    
    • You may test this configuration file by running xbindkeys -v in the terminal.
    • And now try pressing the apple-click combo to activate right-click.
    • Next, try pressing the apple-shift-click to copy and paste linux style: First select some text, then apple-shift-click (known as middle-click or wheel-click) into a text area.
    • last, try shift-delete to delete text ahead of the cursor.
    • cntl-c (within the terminal window) will stop testing.
  5. Finally, run xbindkeys and you are done. xbindkeys will automatically be run with the command /usr/bin/xbindkeys -f $HOME/.xbindkeysrc when lightdm starts. Not sure yet where this is executed from. You might just put a copy of or symlink to your .xbindkeysrc in every user's directory who intends to log in with the mac os keyboard. Note: I had originally posted that you must edit .xprofile to include xbindkeys : but that is not necessary.

Good Luck. -JJ