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.
You can keep the Alt+F4 shortcut if you define a new custom shortcut. Here are three possible solutions:
Using
xbindkeys
andxdotool
Install the packages by opening a terminal and type:
Run
xbindkeys-config
from the terminalPress
New
create a new key binding.Write F1 in the
Key
field to the left or pressGet Key
to grab a key or key combinations. Note that this may create a lot of gibberish such asMod2 + F1 | m:0x10 + c:67
but it still works.Enter into the
Action
field to the left:.... or whatever other key combination you want to execute.
Press
Apply
. It works now.Using Keyboard Settings and
xdotool
Install the
xdotool
package, open a terminal and type:Now define a custom keyboard shortcut using the System Settings Menu:
Set the command to
xdotool getwindowfocus key alt+F4
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:
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: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:
Install
xte
:Create your new shortcut using the System Setting menu as explained for F1 just above but with the following command instead:
Assign F2 to the shortcut, it works from the Shortcut window this time.