Skip to content

Instantly share code, notes, and snippets.

@Elliria
Last active September 22, 2023 19:37
Show Gist options
  • Save Elliria/6925e9e4c92597019aa4eebc86c5a5f7 to your computer and use it in GitHub Desktop.
Save Elliria/6925e9e4c92597019aa4eebc86c5a5f7 to your computer and use it in GitHub Desktop.

CLIPBOARD vs PRIMARY vs SECONDARY

About

  • CLIPBOARD:
    • This contains copied data.
    • Copy data by selecting text and pressing Ctrl+c or right-clicking and choosing copy from the context menu.
    • Paste data by pressing Ctrl+v or pressing Shift+Insert or right-clicking the mouse and choosing paste to paste.
    • AutoKey's clipboard.get_clipboard() and clipboard.fill_clipboard() API calls can access this.
  • PRIMARY:
    • This contains selected data.
    • Its purpose is to contain the only argument to commands that take one argument and is the principal means of communication between clients that use the selection mechanism.
    • Select data by selecting text.
    • Paste data by pressing the middle mouse button.
    • AutoKey's clipboard.get_selection() and clipboard.fill_selection() API calls can access this.
  • SECONDARY:
    • This contains selected data.
    • Its purpose is to either contain the second argument to commands that take two arguments or to contain additional data when there's already a primary selection that the user doesn't want to disturb.
    • Select data by holding down the meta or Alt key while selecting text.
    • Paste data by holding down the meta or Alt key while pressing the middle mouse button.
    • AutoKey doesn't have API calls to access this.

Selecting Text

  • With the keyboard:
    • Hold down the Shift key while pressing any of the arrow keys.
    • Hold down the Shift key while pressing the Home or End button.
    • Hold down the Shift key while pressing the PgUp or PgDn button.
    • Hold down the Ctrl and Shift and End keys.
  • With the mouse:
    • Hold down the left mouse button and drag it across the text.
    • Hold down the left mouse button and lasso the text with the mouse.
    • Double-click to select the current word.
    • Triple click to select the curent line.
  • With the mouse and keyboard:
    • Hold down the left mouse button and press the PgUp or PgDn key.
    • Hold down the left mouse button and press the Ctrl key.
    • Hold down the left mouse button and the Ctrl and Shift and End keys.
    • Hold down the Ctrl key while making multiple selections.
    • Select some text and press the Ctrl and Ins keys together.

More Information

For more details about how all of this works, see the "Peer-to-Peer Communication by Means of Selections" section in the Inter-Client Communication Conventions Manual.

@Elliria
Copy link
Author

Elliria commented Aug 3, 2023

By literals, do you mean <> enclosures?

Yep. Here's the CHANGELOG.rst entry about it. It says:

  It is now possible to place `<code>` and `<code/>` literals in Phrases.
  Additionally, such literals can be typed in scripts using the keyboard.send_keys function.

@Elliria
Copy link
Author

Elliria commented Aug 3, 2023

I had to modify your code a bit, @josephj11, because of invalid syntax (the i++ line) and because I don't trust while loops. I did it this way, starting with only three repetitions so it couldn't run wild:

i = 1
while i < 3 :
    string = str(i) + " [<code" + str(i) + ">]<enter>"
    keyboard.send_keys(string)
    time.sleep(0.1)
    i+=1

My result:

1 []
2 []

Can you make it work? I'm not sure what it should or shouldn't actually be doing.

@josephj11
Copy link

By literals, do you mean <> enclosures?

Yep. Here's the CHANGELOG.rst entry about it. It says:

  It is now possible to place `<code>` and `<code/>` literals in Phrases.
  Additionally, such literals can be typed in scripts using the keyboard.send_keys function.

This is an "existence proof". It shows that the feature exists, but not how to use it. @BlueDrink9 might be able to enlighten us about this. (Maybe there's a working example in the unit tests somewhere.)

Note that the way I tried to use it seemed to work or at least did something without raising an exception.

@josephj11
Copy link

josephj11 commented Aug 4, 2023

The reason I used a much larger range is because I assumed it might similar to ASCII, where the lower ordinals are for non-printable characters. If something like that is going on then the script worked fine. It just didn't run far enough. I'm guessing that this has something to do with keyboard scan codes, but I'm not familiar with them. That doesn't seem to be it either.

I ran it and it looks a lot like a qwerty keyboard, but I'm not sure what standard those codes line up with and it gets weird with a lot of gaps after the normal printable characters.

Sorry for letting that bit of C/bash syntax slip in and break things.

Some of them are control codes. 135 did a clipboard paste. (when I ran the script from 128 to 256).

@Elliria
Copy link
Author

Elliria commented Aug 4, 2023

Yeah, the control codes got the better of me. I tried <code12> in a phrase and keyboard.send_keys("<code12>") in a script and got a 3 in each case, which was proof that it works. My tests with lower numbers hadn't resulted in any output because apparently there aren't codes for those lower numbers. Anyway, since that worked, I tried a few more high numbers and got various characters. As a result, I finally took a chance and ran your code like this:

i = 1
while i < 128 :
    string = str(i) + " [<code" + str(i) + ">]<enter>"
    keyboard.send_keys(string)
    time.sleep(0.1)
    i+=1

It works, but 🛑 is very dangerous code 🛑 that goes out of control, opening and closing windows automatically, etc. I'd either throw a much longer delay onto it to buy you time to end the AutoKey process when it goes out of control (and have pkill autokey in a handy shortcut icon at the ready for doing that so that you can be quick) or be ready to press and hold Alt+PrtSc while typing REISUB in order to reboot your computer when it all goes haywire, as I had to do.

What are the names of these codes so that we can look them up in a chart somewhere and know what they do without trying them? I haven't yet found any kind of character sets that turn a 12 into a 3.

@Elliria
Copy link
Author

Elliria commented Aug 4, 2023

We're actually dealing with two separate things with code. There's the code characters that were described in the previous message.

There are also code literals, which are strings that contain <code> and </code>.

Note: I'm not sure why an example of the <code/> void element was used in the CHANGELOG.rst file, because <code/> is not a valid void element in HTML. I can only assume that that was a typo and should have been the HTML </code> closing tag.

It seems that prior to AutoKey version 0.95.4, if you tried to insert a string literal that contained <code> and </code> into your phrases or scripts, you'd get bad behavior (see below). That was fixed in version 0.95.4 and that's what that CHANGELOG.rst entry above was about.

I downloaded AutoKey version 0.95.0, which was prior to the change, and ran these tests:

  1. I put this into a phrase:
    <code>test1</code>
    <code>test2<code/>
    
  2. I put this into a script:
    keyboard.send_keys("<code>test1</code>")
    keyboard.send_keys("<code>test2<code/>")
    

I got these results:

  • In AutoKey 0.95.0:
    • Phrase result (broken):
      test1</code>
      test2
      
    • Script result (broken):
      test1</code>test2
      
  • In AutoKey 0.96.0:
    • Phrase result (perfect):
      <code>test1</code>
      <code>test2<code/>
      
    • Script result (perfect):
      <code>test1</code><code>test2<code/>
      

@ineuw
Copy link

ineuw commented Sep 22, 2023

Hi. I noticed that no Autokey discussions are taking place on Github, and much thanks to both of you for going out of the way to accommodate me.

My Autokey issues were resolved completely, and because of it, my Wikisource contributions increased exponentially, and restored a much enjoyed pastime. Thus, I avoided disturbing you any further. and hoping to finally post on my Github page about the challenges of installing multiple Linux OS.

@josephj11
Copy link

Great that your workflow works!

Although she may answer for herself here, Elliria has withdrawn from the AutoKey project. Now that Bluedrink9 is also (mostly?) gone, it has gotten really quiet on the project web pages. Sam is still active, but does most of his work off to the side, so we don't see him that often.

@Elliria
Copy link
Author

Elliria commented Sep 22, 2023

That's terrific news, @ineuw. I'm so glad everything worked out and that you're able to up your contributions. And you're never a disturbance. It's always a pleasure to hear from you.

As @josephj11 pointed out, I'm no longer contributing to the AutoKey project, but hopefully some others will eventually join in to help out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment