Home>

Please note that there are inevitably many jargon because it contains a lot of relatives (although not exactly).

Premise

There are A and B, and A and B are copied alternately. When A is changed, B also changes, but since B sometimes becomes the same, I am trying to make something that does not perform the process x described later when it becomes the same continuously. I was worried for dozens of hours and couldn't do it after all, so I ended up throwing a ball m (_ _) m

import pyperclip as pyc
while True:
    if pyc.paste (). startswith ("a"): copy #A
        i = pyc.paste ()
        while True:
            if pyc.paste (). startswith ("b"): copy #B
                try: try:
                    print (i) # processing x
                    break
                except:
                    print (traceback.format_exc ())
                    break
            else: else:
                continue
    else: else:
        continue
Addendum

Since A increases one by one, there is a possibility that it can be realized by using it if i am young.

I couldn't put up an image in the reply, so here. I can't explain it to my vocabulary, so make it a gif.

  • Answer # 1

    I watch the clipboard in a loop and keep reading the same value all the time,
    Not processing when it is continuous means
    Do you want to earn the timing when the contents change?

    If you use waitForNewPaste (),
    You can block the process until the contents of the clipboard change.


      if pyc.paste (). startswith ("a"): copy #A
            i = pyc.paste ()

    If the contents of the clipboard change after checking with startswith
    The variable i may not start with "a", so
    If you want to be strict, it is better to store it in a variable and then check it with an if statement.

  • Answer # 2

    You may have misunderstood what you want to do, but why not keep the previous value of b and check if it's the same?

    import pyperclip as pyc
    prev_b = None
    while True:
        if pyc.paste (). startswith ("a"): copy #A
            i = pyc.paste ()
            while True:
                x = pyc.paste ()
                if x.startswith ("b"):
                    try: try:
                        if x! = prev_b:
                            prev_b = x
                            print (i) # processing x
                        break
                    except:
                        print (traceback.format_exc ())
                        break
                else: else:
                    continue
        else: else:
            continue