You definitely canβt update the clipboard in a loop and expect the data to be available (and available for your application) immediately. The application that you send the keystroke runs in its own process, and the windows are multi-processor, multi-thread, etc. Therefore, you are looking for an updated clipboard before another application gets a chance to copy it.
In addition, since the system may have other programs that control the clipboard for updates (clipboard), you will encounter these programs when trying to get data from the clipboard.
I donβt know why you are trying to do what you are doing, but you must know that it will not work all the time. You may be able to make it work in some cases, but not in all cases. If this is not a training exercise for your own use, you should abandon this approach.
And please read this quote on the topic:
"Programs should not transfer data to ours from the clipboard without explicit instructions from the user."
- Charles Petzold, Windows 3.1 Programming, Microsoft Press, 1992
source share