2

I have a keyboard with dedicated keys for XF86Cut, XF86Copy, XF86Paste. I want to bind these to Emacs commands. The goal is get the usual behavior for cut-and-paste between Emacs, my terminal, and my browser Firefox with a common set of keys.

FWIW, XF86Paste works seems to work just fine with zero configuration. However, Emacs cannot see the key presses for the other keys. I verified this using M-x describe-key followed by a key press. For XF86Copy and XF86Paste, Emacs behaves as if no key was pressed

Both XF86Copy and XF86Paste work in the terminal. (However, XF86Cut doesn't.) How can I bind XF86Cut and XF86Copy to commands within Emacs?

This is how I start Emacs: emacsclient -a "" -t

I'm using:

  • Emacs 27.1
  • Alacritty 0.5.0 (a6681e3a)
  • xmonad 0.15
  • X.Org Server 1.20.9-2
  • Linux 5.9.1.arch1-1
Charles R
  • 121
  • 2
  • Please clarify what you mean by "However, Emacs cannot see the key presses for the other keys": if Emacs really doesn't receive those events, then there's nothing you can do on Emacs's side. But the fact that "Both XF86Copy and XF86Paste work in the terminal" suggests that Emacs should receive some event when you press XF86Copy. – Stefan Oct 23 '20 at 14:19
  • `M-x describe-key` followed by a key press. For XF86Copy and XF86Paste, Emacs behaves as if no key was pressed. – Charles R Oct 26 '20 at 19:13
  • Please put those extra details directly in your question (by editing it) rather than in comments. Also, the fact that you start Emacs via `emacsclient .. -t` suggests you're using Emacs within a text-terminal, so most likely those keys are caught by your text-terminal, which is why Emacs never sees them. I'd recommend you remove the `-t` and run Emacs in its own GUI frame. – Stefan Oct 26 '20 at 21:45
  • I've recently switched to Wayland. GUI Emacs doesn't support Wayland. – Charles R Oct 28 '20 at 01:57
  • AFAIK you can still use the GUI interface via Xwayland – Stefan Oct 28 '20 at 02:53
  • You should add this [Gui Emacs doesn't support Wayland ref](https://emacs.stackexchange.com/q/48561/5223) Which points to the devel thread showing emacs is not properly gtk (I've recently [been bitten!](https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-10/msg01867.html) ) – Rusi Oct 28 '20 at 03:53

1 Answers1

1

With a sun keyboard, for me, it works quite straight forward.

(global-set-key (kbd "<XF86Paste>") 'yank)
(global-set-key (kbd "<XF86Copy>") 'kill-ring-save)
(global-set-key (kbd "<XF86Cut>") 'kill-region)

For the terminal integration, that's related to the OS itself and how it manage the keyboard input, this article may help

Fermin MF
  • 635
  • 3
  • 8