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.

@josephj11
Copy link

josephj11 commented Jul 1, 2023

Mine does. They used to be subfolders in almost all categories, but now I only see one in my Internet category. Here's a (very poor) screenshot. You can barely see it at the bottom of the screen.

You have to initially add the new folder at the very end of the menu. Adding it anywhere else makes it a submenu of the category above it. Took quite a while to figure out how to avoid that.
Selection_089

@Elliria
Copy link
Author

Elliria commented Jul 4, 2023

Ah, I see what you mean. It's a sub-folder inside of each of the folders. I guess I've never seen it because I don't have enough applications inside of any of my folders. It would probably show up if I filled one of my folders.

@ineuw
Copy link

ineuw commented Jul 4, 2023

My sincerest thanks to both of you @Elliria, @josephj11, for guiding me through the minefields of ignorance and assumptions over these past years. I haven't posted anything since I found the solution, because I am busy working on Wikisource ever since. A good reason that kept me quiet.

I am preparing another post to explain what the solutions were, relating to the clipboard, copy and paste. This will include browsers which have their own additional mouse control. Essentially, I laid down rules to follow and test them by process of elimination.

I am going through the open issues, and going back all the way to 2017. There are issues which are closed but still appear on the open list? May I close others as well? It doesn't look good that we have so many old and irrelevant issues.

Also, I want to help those with issues I understand and similar to my own.

@Elliria
Copy link
Author

Elliria commented Jul 5, 2023

You're doing great, @ineuw. Your dedication, determination, thoroughness, and relentless pursuit for the answer to any puzzle is much appreciated.

I'm not sure what's up with closed issues being shown as still open, but that sounds like a bug in GitHub. Believe it or not, those can be reported here. I had a heck of a time finding it and am still astounded that they use that method instead of their own issue-report interface.

@josephj11
Copy link

May I close others as well? It doesn't look good that we have so many old and irrelevant issues.

Also, I want to help those with issues I understand and similar to my own.

You can comment on any issue, but only maintainers can modify other people's issues by editing, closing, labelling...

You don't seem to need that level of access, but I'm open to discussing it.

For now, you can post a comment in any issue that needs attention and recommend what actions should be taken. If I have already participated in that issue, I'll get notified when you comment. If I haven't partcipated in it, you can tag me in your comment with an @josephj11 and I'll get notified that way. The same is true for our other maintainers (@Elliria hasn't requested maintainer status yet, so she's in the same boat as you are).

@ineuw
Copy link

ineuw commented Jul 5, 2023

No thanks, I am not qualified, and don't wish to have that decision making power. I will tag them as you suggested.

@ineuw
Copy link

ineuw commented Jul 16, 2023

@Elliria and @josephj11, I am slowly beginning to catch up to my backlog of unanswered posts. Every script provided was tested, and every software suggestion was analyzed in comparison to what I am using, and will comment on them as time permits.

My first preference is to add the wiki "wrap codes" by counting the string length. It is simple and elegant. and I don't need to rely on the clipboard.

The script and the results of your script in my GitHub discussion page and I think you can access it. It didn't feel right to mess up your pages here. Let me know if there is a problem.

I discovered that the browser textboxes behave the same way as that of Wikipedia/Wikisource. This is what I wanted to show you and the Wikimedia tech support. Otherwise, my communicating with them is very difficult without details. Now, I have independent proof.

@josephj11
Copy link

@ineuw your link above is broken.

What probably happened is that if you create a link without the protocol prefix (http://) GitHub "improves" it for you, which often makes it point nowhere real and its never where I want it. I ran into this a bunch of times before I figured out how to avoid it.

@ineuw
Copy link

ineuw commented Jul 17, 2023

Please try it now. It was private and learning how to manage it. In case you didn't see the <ref> codes, I added the ticks.

@Elliria
Copy link
Author

Elliria commented Jul 17, 2023

I checked it out and added some comments.

@ineuw
Copy link

ineuw commented Jul 29, 2023

I am slowly catching up with your recommendations and want to thank you for the suggestions. Installed Geany and it's an excellecnt code editor and superior to Kate in its simplicity. I set it as my preferred editor instead of Pluma. I couldn't get Microsoft Net compiled, so, I installed Pinta from snap. It has some very interesting features but the app needs to be explored and learned.

Then, I installed 'black' and tested all 93 Autokey files. It found two scripts with an error, which I corrected. It also reverted my single quotes to double which is OK, except double quotes fail when Autokey pastes Wikipedia wiki codes like <ref> in the browser. Then the single quote is necessary. I just made it my universal rule, considering my working environment.

@Elliria
Copy link
Author

Elliria commented Jul 29, 2023

I'm glad you like Geany. It's deceptively simple, yet incredibly powerful under the hood. If you ever end up messing around with some of the things it can do and need some help, feel free to let me know. I've used it for years and adore it.

Pinta is another of my favorite programs and is among the first things that I put onto my machine after a fresh installation of the operating system. Just like Geany, it seems deceptively simple, yet is incredibly powerful under the hood.

I haven't tried black - had never heard of it, actually. But after looking it up, I don't think I would. You have to hand it the steering wheel and let it drive. I've always resisted such things, so I'll stick with tox and flax8.

@ineuw
Copy link

ineuw commented Jul 29, 2023

I am at an early stage of proper code management, but I gained knowledge of one approach, and now I am returning to tox and flax8 for comparison. I never tried any of these tools before.

I revised my original stance on single quotes since I first posted about them in Autokey discussions. While black reverted all my single quotes to double, which is OK, except in cases where the greater than and less than signs are in the pasted text as well.

@josephj11
Copy link

IDK what it will do, but you might try escaping the < and > with backslashes as \< and \>. Depending on your context, that might fix things.

If you want to get really weird, you could also replace them with their Unicode code points or use AutoKey <code> macros. (This is serious overkill, but you never know when something weird like this might help in an edge case.)

@Elliria I just tried to find the code macro in our docs and couldn't find it. Do you know where it is? I expected to find it with the other macros, but didn't see it there.

@Elliria
Copy link
Author

Elliria commented Jul 30, 2023

I use double quotes most of the time so that anything with apostrophes inside of them will just work, but will make exceptions for times when the contents are surrounded in double quotes or start with one.

Do you have an example of the <code> macro in use, @josephj11? I don't see it in the wiki, either. We have the new system command macro in AutoKey v0.96.0. Example:

<system command='echo test'>

Is that what you're thinking of?

As a side benefit, when I went poking around in the documentation to try to find it, I found a typo, which has now been fixed.

@josephj11
Copy link

josephj11 commented Aug 1, 2023

No, but here it is in interface.py. (Line 1140 in master branch)

    def __lookupKeyCode(self, char: str) -> int:
        if char in AK_TO_XK_MAP:
            return self.localDisplay.keysym_to_keycode(AK_TO_XK_MAP[char])
        elif char.startswith("<code"):
            return int(char[5:-1])

Looks like it's <code####> where #### is a decimal character code (not a fixed number of digits).

I tried something "obvious" and got no errors, but not what I was expecting.

I'm out of time for now, but sort of got it working.

keyboard.send_keys("[<code41><code42><code43>]")

yielded

[fgh]

but 31,32,33 yielded [iop] which line up on my keyboard, but otherwise is quite puzzling.

@Elliria
Copy link
Author

Elliria commented Aug 2, 2023

It looks like this was a new feature created in AutoKey 0.95.4 that lets us put <code> and </code> literals in phrases and also type them with keyboard.send_keys() in scripts.

As you pointed out, the code for this is in lines 1140 to 1150 of the interface.py file. The git blame doesn't show who created the class. It's just showing who has touched the code.

git_blame

I haven't yet been able to figure out how to work them. I tried inserting Unicode, Bash, Python, and AutoKey API calls and none of it worked. If you decide to play around with them and figure them out, you'll be my hero.

@ineuw
Copy link

ineuw commented Aug 2, 2023

By literals, do you mean <> enclosures?

@josephj11
Copy link

josephj11 commented Aug 3, 2023

@Elliria It's code as in some sort of character code, not program code.

When it detects <code, it takes a substring starting at character 5 (just past <code and goes to one char short of the end of the string which suggests that it's stopping just before the matching > and turning that into an integer character ordinal or scan code, etc. I don't believe this uses a block command syntax like in html or xml. There is no <\code>.

If I couldn't figure out what it does from reading more of the AutoKey code (starting with that keysym_to_keycode array and the AK_TO_XK_MAP array) ...

What I would do is write a script that iterates from 1 to 127 (to start with) and shows what each code does.

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

and run it in an empty text editor window.

That should generate the range of values it emits so we can see a pattern pointing us to what those values correspond to.
Based on my initial tests, it looks similar to ASCII, but it doesn't quite line up.

If that doesn't work, you might have to do it as several separate substrings, etc.

This assumes we're dealing with a single byte code, not a multibyte one like UTF-8. That might not be a valid assumption.

@josephj11
Copy link

@ineuw

By literals, do you mean <> enclosures?

I need a quoted reply or other context to figure out what this refers to.

@ineuw
Copy link

ineuw commented Aug 3, 2023

I was referring to HTML codes enclosed with < and > characters in scripts? That is what I meant by literals. What did you mean?

BTW, when I changed double quotes to single quotes in all my scripts, my problem of copy and paste with wrappers disappeared. That is why I am not here complaining. My Wikipedia editing activity increased noticeably.

I still owe you the link to the discussion where enclosing with single quotes preserves the original content, was mentioned. I also collect tons of bookmarks to online discussions and sorting through them daily.

@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