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

25,578

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

Share:
25,578

Related videos on Youtube

Cerin
Author by

Cerin

Updated on September 17, 2022

Comments

  • Cerin
    Cerin over 1 year

    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.

    • bahamat
      bahamat almost 12 years
      On the Mac it's natively the ctrl key, not command. The command key will translate to the "super" key in X terminology.
  • Cerin
    Cerin over 13 years
    What do you mean by "Try the Option Key"? If you mean press that key, yes, I've tried all the keys, and none appear to be configured to trigger the context menu by default. Is there a way to configure this in Ubuntu?
  • funk-shun
    funk-shun about 13 years
    I think he meant try left-clicking while holding down the ALT...
  • Cerin
    Cerin about 11 years
    That doesn't work for me on Ubuntu 12.04.
  • Cerin
    Cerin over 10 years
    Actually, it's Fn+Shift+F10.
  • Cerin
    Cerin over 10 years
    I don't understand, what is this supposed to do? It doesn't seem to have any effect on 12.04. I'd like the right command key to trigger the context menu. Why are you telling me to test by clicking the ctrl+mouse?
  • JJ Stiff
    JJ Stiff over 10 years
    Cerin- I am using 13.10 so I cannot assure you this solution will work on 12.04: I was telling you to ctrl-mouse click (now option-mouse click) as a method for testing your work - at that point the secondary mouse click functionality should be working. If you would prefer to just use a different key (ie control only), use xbindkeys --key to help figure out what the key combo should be.
  • JJ Stiff
    JJ Stiff over 10 years
    Cerin- reading the edit on your post: did you make sure to 'sudo apt-get install xdotool' ? You should also be able to run 'xdotool click 3' from the terminal and have it pop up the context menu right where the mouse is located. Also: not sure why you are choosing 'm:0x50 + c:134' as your key combo: look at the examples which are provided when you 'xbindkeys --defaults > ~/.xbindkeysrc' (IE: do 'less ~/.xbindkeysrc' in the terminal)
  • NReilingh
    NReilingh over 10 years
    @Cerin Fn would only be necessary if your F10 key wasn't actually an F10 key...
  • Cerin
    Cerin over 10 years
    @NReilingh, Yes, by default it's the mute key. Thus my comment.
  • NReilingh
    NReilingh over 10 years
    @Cerin But that's user-specific. The application is just looking for shift+F10. The way your system is configured, you send an F10 by hitting Fn+mute.
  • rightparen
    rightparen about 7 years
    If you add "+ Release" to the binding, it triggers when you release the mouse button and you don't need the 'sleep' call. For example, to emulate OSX's control-click behavior, set the command to just "xdotool click 3" with trigger "Control + b:1 + Release".
  • Waldir Leoncio
    Waldir Leoncio almost 7 years
    Good shortcut; unfortunately, it corresponds to a right-click on the active window, not where the mouse is pointing.
  • Genko
    Genko about 2 years
    That's not entirely true. It is the active window IF you don't have your mouse cursor in a specific spot. I mean the caret specifically. If you're typing an email for example and the caret is on a specific word it'll open right on that word. If you're in a newly opened window and haven't selected an input field or anything then it will open on the page. If you tab to a specific item on the page it opens for that (though may not be directly on it.) It's relative to what has focus.