Linux: Set F2 F3 F4 to Cut Copy Paste

By Xah Lee. Date: . Last updated: .

This page shows you how to set {F2, F3, F4} keys to do {Cut, Copy, Paste} globally.

linux x11 virtual keyboard xvkbd

xvkbd is a virtual keyboard for X window system. It is useful as a shell command tool to send keys.

xbindkeys is a tool to let you bind keys to shell commands.

# Install xvkbd (virtual keyboard)
sudo apt-get install xvkbd
# install xbindkeys
sudo apt-get install xbindkeys

Create a file at ~/.xbindkeysrc.

Add the following content:

# ~/.xbindkeysrc

# make F2 do Ctrl+x
"xvkbd -no-jump-pointer -xsendevent -text '\Cx'"

# make F3 do Ctrl+c
"xvkbd -no-jump-pointer -xsendevent -text '\Cc'"

# make F4 do Ctrl+v
"xvkbd -no-jump-pointer -xsendevent -text '\Cv'"

# make F11 do Ctrl+PageUp
"xvkbd -no-jump-pointer -xsendevent -text '\C\[Prior]'"

# make F12 do Ctrl+PageDown
"xvkbd -no-jump-pointer -xsendevent -text '\C\[Next]'"

# make F14 do Ctrl+w
"xvkbd -no-jump-pointer -xsendevent -text '\Cw'"

Now, reload the config file.

# make xbindkeys reload config
killall -s1 xbindkeys

in case you need to restart it, do:

# restart xbindkeys daemon
killall xbindkeys
xbindkeys -f ~/.xbindkeysrc

Or, log out and log in again.

Here's quick explanation of how it works.

For each keybinding in this example, the xbindkeys config takes 2 lines.

The shell command, is calling the tool xvkbd, which sends a key signal.

Here's the syntax for the keys used in xvkbd.

xvkbd key syntax
\SShift (modify the next character)
\CControl (modify the next character)
\AAlt (modify the next character)
\MMeta (modify the next character)
\[keysym]keysym is X11's key syntax. (For example, \[Left]) 〔►see Linux: X11 Keyboard Key Names〕 For 【Shift+Tab】, use \[ISO_Left_Tab]
\Ddigitdelay digit * 100 ms
\xvaluemove mouse pointer (use "+" or "-" for relative motion)
\yvaluemove mouse pointer (use "+" or "-" for relative motion)
\mdigitsimulate click of the specified mouse button

(thanks to XueFuqiao for help.)

Linux Keybinding Topic

  1. Linux: Keyboard Software Guide
  2. Linux: Swap Control Alt Keys, xmodmap
  3. Linux: Set F2 F3 F4 to Cut Copy Paste
  4. Linux: Swap CapsLock Escape Keys
  5. Linux: Make CapsLock Do Home Key
  6. Linux: Setup Shift Lock Key
  7. Linux: Add Keyboard Shortcut to Switch App
  8. Linux: Set Key Repeat Rate
  9. Linux: Set System Keyboard Layout
  10. Linux: How to Switch to Dvorak Keyboard Layout
  11. Linux: Change Volume by Command
  12. Linux: xmodmap Tutorial
  13. Linux: Xbindkeys Tutorial
  14. Linux: Find Keyboard Key Scancode
  15. Linux: X11 Keyboard Key Names