1

We are writing a Python application that relies on copying and pasting content from the top windows. To do that we issue sendkey commands: Ctrl-Esc for going to the previous windows Ctrl-A followed by Ctrl-C to copy all text from the window And Cnrl-V to paste the the clipboard content to the top window. Unfortunately at times we run into timing problems.

Is there some way to queue the SendKey commands so that Cntl-A waits for Alt-Esc, and then Cntl-C waits till Cntl-A is done? Or perhaps there is a way to know when each command is finished before sending the next one?

Thank you in advance for your help.

Veet Vivarto
  • 371
  • 3
  • 11
  • Is the overall speed an issue - instead of working out times, isn't it an option just to add sleep for a second after the Ctrl-A ? – Iliyan Bobev May 16 '13 at 15:41
  • Yes, you are right, adding enough sleep() does help however this is a a clumsy solution. Firstly people have different computers, but more importantly once in a while any computer could be busy doing something. There is no way to know how long sleep is needed in each given situation. – Veet Vivarto May 16 '13 at 16:12
  • Well, I believe that the commands like Ctrl-A are handled on OS level, so in order to ensure that they are complete before sending the next one, you will need to query some system process. Those could be hard to identify, and such a query will differ from OS to OS. Have you considered different transfer method besides sendkey commands? – Iliyan Bobev May 16 '13 at 16:24
  • I am open to any suggestions: Perhaps we can figure out how can we bring the previous window to the top without using SendKey. (Though it will not be easy.) But how can we select all text in any given application without using Cntrl-A (or a mouse command). How can we copy all selected text in any give application other than by using Cntrl-C (or the mouse). Cntrl-A, Cntrl-C, Cntrl-V, seem to work in all applications. I don't know of any other way to do that. Do you have any suggestions? – Veet Vivarto May 16 '13 at 18:37
  • the whole premise is strange. If you have one specific application you should check for other channels to transfer the data between the app and python - files, network, DB or API. If your python program has to work with different apps - you should look for some alternative approach that will be more integrated with the OS. Can you give the name (or example) of the application you are copying from? – Iliyan Bobev May 17 '13 at 16:38
  • Here is where we are copying from: browsers like Chrome, Firefex, I.E. etc especially from Webmail e.g. Gmail, Hotmail, Yahoo, etc. Additionally copying from from various word processors and editors e.g. Word, Open Office, Notepad, etc. I can't think of any other way to grab the information from so many different sources. – Veet Vivarto May 17 '13 at 23:55
  • If you have IE, then you're on Windows. Try the suggestions from [this answer](http://stackoverflow.com/questions/3468261/emulate-user-activity) If subsequent processing is needed, use the emulator to save all in a txt file that Python can easily process. – Iliyan Bobev May 20 '13 at 17:08

1 Answers1

0

No, I don't think so. You're talking about separate message queues here. Alt+Esc is a global hotkey, presumably handled by windows explorer. Ctrl+A and Ctrl+C are handled by the source app, and should be processed in order. However, there will be a lag after the Ctrl+C, as the clipboard must be locked, cleared, and updated, and then clipboard notification messages are sent to all applications registered on the clipboard notification chain, as well as the newer clipboard notification API. After all of those applications have had a chance to react to the data, THEN it is safe to paste with Ctrl+V.
Note that if you're running any sort of remote desktop software, you also have to wait for OTHER SYSTEMS to react to the clipboard notification, which will include syncing clipboard data across the network. Now you see why this is hard. Sorry for the bad news.

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62