2

I try to optimize everything. One thing I do frequently is closing windows and closing tabs. Is it possible to set the F1 button to close windows in Ubuntu 14.04? (i.e. same behavior as ALT+F4) And scroll lock or F2 to close tabs (i.e. same behavior as CTRL+W)

Using the Keyboard --> Shortcuts, the F1 simply opens the help menu for the keyboard application. It cannot set it as shortcut "value". And there's no entry for closing tabs.

The latter may be application-specific. So a keyboard intercepter solution may be the way to go. If possible, I'd like ALT+F4 etc. to keep working.

3

You can keep the Alt+F4 shortcut if you define a new custom shortcut. Here are three possible solutions:

Using xbindkeys and xdotool

  1. Install the packages by opening a terminal and type:

    sudo apt-get install xdotool xbindkeys xbindkeys-config 
    
  2. Run xbindkeys-config from the terminal

    enter image description here

  3. Press New create a new key binding.

  4. Write F1 in the Key field to the left or press Get Key to grab a key or key combinations. Note that this may create a lot of gibberish such as Mod2 + F1 | m:0x10 + c:67 but it still works.

  5. Enter into the Action field to the left:

     xdotool getwindowfocus key alt+F4
    

    .... or whatever other key combination you want to execute.

  6. Press Apply. It works now.

Using Keyboard Settings and xdotool

  1. Install the xdotool package, open a terminal and type:

    sudo apt-get install xdotool
    
  2. Now define a custom keyboard shortcut using the System Settings Menu:

    enter image description here

    Set the command to xdotool getwindowfocus key alt+F4

  3. The next step requires to go back to the command line as you can't type F1 to define a new accelerator. So list all the defined custom shorcuts with:

    $ dconf list /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/
    custom0/
    custom1/
    

    The one you've just created should be the last one, here custom1. Type the following command to assign F1 to close the active window:

    dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/binding "'F1'"
    

    Adjust the custom<id> to match yours.

Your new F1 shortcut is ready to use (needless to log out or restart your system) and Alt+F4 still works.

Using Keyboard Settings and xte

For keys without special meaning to the Keyboard-application (like F2), you don't have to go through command line to do the key binding:

  1. Install xte:

    sudo apt-get install xautomation
    
  2. Create your new shortcut using the System Setting menu as explained for F1 just above but with the following command instead:

    xte 'keydown Control_L' 'keydown w' 'keyup Control_L' 'keyup w'
    
  3. Assign F2 to the shortcut, it works from the Shortcut window this time.

  • I do not have an `/org/`` directory so the dconf write step returns error: 0:expected value. I did however make the key binding of the xdotool call work with xbindkeys (using the xbindkeys-config interface). That was a bit easier than having to go command line but does require installing xbindkeys. You're welcome to update your answer with that solution or I can do it. I will accept your answer when there's a working solution. Thanks a lot! – Jonas Lindeløv Feb 13 '15 at 10:51
  • @JonasLindeløv I fixed the command (missing quotes around "'F1'"). The /org/... is not a path but a schema path used inside the dconf database. – Sylvain Pineau Feb 13 '15 at 10:55
  • It works! I've updated the answer with the xbindkeys-config which is the solution I chose. I hope it's ok. – Jonas Lindeløv Feb 13 '15 at 11:24
  • @JonasLindeløv Just approved your edit, thanks. – Sylvain Pineau Feb 13 '15 at 11:24
  • @SylvainPineau: you're a treasure-trove of knowledge! Upvoted and Q favourited! – Fabby Feb 15 '15 at 13:08

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.