5

Before switching to Ubuntu I used to use AutoHotkey for the sole purpose of pasting from my clipboard, the simple command was:

 ~f2::
clipboard = %clipboard%
send %clipboard% {enter}

or something along those lines. Does anyone have a similar script for Autokey?

αғsнιη
  • 35,660
Steve Urkel
  • 51
  • 1
  • 3

2 Answers2

5

I've found that we can do it by script like this:

content = clipboard.get_clipboard()
keyboard.send_keys("wrapping text %s wrapping text" % content)

Then the script can be used by an abbreviation or a hotkey which you can set on it.

  • 2
    This is different than pasting from the clipboard. Instead, it is typing what is in the clipboard. This doesn't always work for me; it sometimes loses keystrokes in remote RDP sessions. How can you instead automate pasting the whole clipboard contents at once, without having to press ctrl-v yourself? – Lonnie Best Aug 04 '22 at 17:06
  • Nowadays I think you can try Powertoys program for Windows 10+. It's just a guess, but recently I successfully used it as a keyboard remapper, maybe it has some clipboard managing capabilities too – Dmitry Davydov Aug 06 '22 at 04:23
  • 2
    I'll keep that in mind for Windows, but what about Linux? – Lonnie Best Aug 06 '22 at 05:36
  • 1
    @LonnieBest Did you find a better linux solution? – vishvAs vAsuki Oct 09 '22 at 04:49
  • @vishvAsvAsuki - You can fill the clipboard using clipboard.fill_clipboard(stringName), and then press ctrl-v to paste what's in the clipboard as a whole instead of sending each individual key like keyboard.send_keys() does. I never figured out a way to make Autokey paste from the clipboard without typing ctrl-v myself. If you know how, please tell me. – Lonnie Best Oct 10 '22 at 05:16
  • @LonnieBest Added an answer https://askubuntu.com/a/1434833/24458 – vishvAs vAsuki Oct 11 '22 at 07:58
  • 1
    @LonnieBest The reason the above (wrong) answer doesn't behave as expected is because the API call is asynchronous and returns immediately before it has actually done anything. The simple fix for this is to add a delay after any clipboard API call with something like time.sleep(0.1). Interspersing delays in your scripts tends to solve a lot of problems, especially with applications that can't accept input as fast as AutoKey can send it. – Joe Feb 12 '23 at 13:17
1
keyboard.send_keys("<ctrl>+v")

Also, for phrases, be sure to select this option:

enter image description here

  • 1
    Phrases aren't involved here, but when you do use them, the above option should always be your first choice unless your phrase contains macros such as <down> or <cursor>. As of AutoKey 0.96.0, this is the default for new phrases as it avoids a lot of potential probems. – Joe Feb 12 '23 at 13:06