最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to insert text into Windows Text Controls - Stack Overflow

programmeradmin2浏览0评论

I am trying to become more familiar with programming GUI applications on Windows that interface with the OS. As a starting project, I want to build an App similar to Grammarly. The app should do the following:

  1. Monitor text input in any active textbox
  2. When triggered (either automatically or via a keyboard shortcut), it will send the contents of the current textbox to a backend
  3. Run it by the GPT API to correct mistakes
  4. Insert the corrected text back into the active textbox

Steps 1 and 2 work fine, I am using pywinauto.Desktop(backend="uia").window().descendants() to find the descendant that has_keyboard_focus() and extract the text.

However, I am having trouble with re-inserting it. Replacing the text using pywinauto did not work in all applications, so currently I am just sending ctrl+a and ctrl+v. This is unreliable as it takes time and sometimes ctrl+a gets sent too late, resulting in duplicate text.

Also, in the future, I want to use this, e.g., in Word, and it should not always replace the whole document, but only the current paragraph or the current selection. What is a better way to insert text back into Windows text controls?

发布评论

评论列表(0)

  1. 暂无评论