<p style="box-sizing: border-box; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; margin-top: 0px !important;">Dear pywin32 group:</p><p style="box-sizing: border-box; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; margin-top: 0px !important;">Recently i bump into a case where i cannot get text from a window field directly.<br style="box-sizing: border-box;">So i try to type ctrl+a and ctrl+c , and then use win32clipboard to read data from clipboard<br style="box-sizing: border-box;">However, i always get data from the previous "ctrl+a ctrl+c", not the latest one<br style="box-sizing: border-box;">In order to get the latest clipboard data , i have to perform "ctrl+a ctrl+c" in another thread<br style="box-sizing: border-box;">Should this be a bug?</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";">FYI ,I'm using Windows10 , Python 3.6.4rc1</p><pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px; margin-top: 0px; word-wrap: normal; padding: 16px; overflow: auto; line-height: 1.45; background-color: rgb(246, 248, 250); border-radius: 3px; color: rgb(36, 41, 46); margin-bottom: 0px !important;"><code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; padding: 0px; margin: 0px; background: transparent; border-radius: 3px; word-break: normal; white-space: pre; border: 0px; display: inline; overflow: visible; line-height: inherit; word-wrap: normal;">def chooseAndCopyResult(app,windowName,editIdx):
allEdits = app.window(title_re='.*{}.*'.format(windowName)).children(control_type='Edit')
allEdits[editIdx].set_focus().type_keys('^A').type_keys('^C')
#this one does not return the latest clipboard but the previous clipboard
def readResultFromOCR(app,windowName,editIdx):
chooseAndCopyResult(app,windowName,editIdx)
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
return data
# this one works, and get the latest data from clipboard
def readResultFromOCRWorking(app,windowName,editIdx):
thread = Thread(target=chooseAndCopyResult,args=(app,windowName,editIdx))
thread.start()
thread.join()
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
return data</code></pre>