1

If I look under Settings >> Keyboard >> Shortcuts, I don't see anything related to Control-C, -X or -V. Where are they defined? And how? Suppose I want to change their actions to some other shortcut key, how would I do it?

With help in the comments, I am able to define a hotkey to do the paste action using xdotool: xdotool key --clearmodifiers ctrl+shift+v.

In addition, I would like to add a script: xdotool key --clearmodifiers ctrl+shift+v && some_script. That fails, but with further help from the comments, I'm finding that /bin/bash -c "xdotool key --clearmodifiers ctrl+shift+v && some_script" does work!

Diagon
  • 460
  • 3
  • 18
  • They're implemented internally by the desktop environment and I don't think you can change what they do. Even if you bind a shortcut to Ctrl V, it will still perform pasting action. Although there may be tricks to get around it, though I'm not aware which specifically. – Sergiy Kolodyazhnyy Sep 12 '18 at 09:49
  • Thanks @Sergiy. Is there a way to bind control-v's action to some other key? What is, in other words, control-v's action? – Diagon Sep 12 '18 at 09:56
  • Not really. At least not under GNOME, I don't know about others. The best I can do is make a "copy" of paste, so you can have Ctrl V amd some other key. – Sergiy Kolodyazhnyy Sep 12 '18 at 09:58
  • You mean I can define, say control-y to be control-v? That would be fine for my purposes. How would I do that? – Diagon Sep 12 '18 at 09:59
  • I mean Ctrl+V doing pasting and Ctrl+Y doing pasting. Same action, two different keys. There's a command called xdotool which allows you to simulate keypresses, among other things. So you bind that command with required options to a shortcut, and when you press Ctrl Y, it'll say to desktop environment "Ctrl V was pressed, do your thing". – Sergiy Kolodyazhnyy Sep 12 '18 at 10:12
  • @Sergiy - ok, xdotool key ctrl-l works in a terminal window. xdotool key ctrl-shift-v sort of works, but actually pastes twice. When I try to define either to a hotkey, it fails. Thoughts? – Diagon Sep 12 '18 at 10:40
  • Hi Diagon, the issue is that if you asign a keyboard shortcut to another keyboard shortcut, you are virtually pressing both. If you add a small break of 0.5 sec, it should work if you release the shortcut immediately. Not perfect, but it works. – Jacob Vlijm Sep 12 '18 at 11:06
  • @Jacob - That is indeed working, as long as I release immediately. Do you have thoughts on how I might do something like xdotool sleep 0.5 key ctrl+v; some_script? Adding the script fails, though running the script along with that hotkey, works. – Diagon Sep 12 '18 at 11:13
  • xdotool key --clearmodifiers ctrl+shft+v also seems to work, but fails when I add the script. – Diagon Sep 12 '18 at 11:27
  • /bin/bash -c "sleep 0.5 && <xdotool command>" should work from a shortcut. – Jacob Vlijm Sep 12 '18 at 11:53
  • I remembered this one: https://askubuntu.com/questions/872695/how-to-create-a-shortcut-that-executes-an-xdotool-command-to-simulate-a-key-pres/872698 – Jacob Vlijm Sep 12 '18 at 11:56
  • @Jacob - thank you, yes. I had read that one. Note that I am wanting to add a script to eg the paste command. xdotool in a shortcut is now working, but that in combination with a working script, is not working. – Diagon Sep 12 '18 at 18:36
  • @JacobVlijm - ok, it seems to be working as "/bin/bash -c "<xdotool_command> && some_script". If you want to write that up as an answer, I'd accept it! (I put the answer in the question, but you can move it into an answer.) – Diagon Sep 12 '18 at 18:58
  • 2
    I didn't answer here, because the answer is in the linked dupe :) – Jacob Vlijm Sep 12 '18 at 19:12

0 Answers0