[英]Pressing keys with python win32api
我試圖在 PYTHON 2.4 腳本中實現以下行為,這里是步驟,然后是問題:
因此,在第 5 步和第 7 步中,我想要做的是模擬按 Alt+Tab 鍵以返回腳本窗口(在第 5 步中),然后再次返回到“Z”程序的窗口(在第7)。 問題是我不知道如何實現這一點(模擬按 alt+tab 鍵),並且沒有找到我疑惑的答案。 我正在使用 python win32api 模塊將鼠標定位在某個點並進行點擊,但我沒有找到模擬按鍵的方法。
試試這個:
1)使用: https : //gist.github.com/chriskiehl/2906125
2)
import win32api
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("app")
win32api.Sleep(100)
shell.AppActivate("myApp")
win32api.Sleep(100)
shell.SendKeys("name")
win32api.Sleep(500)
shell.SendKeys("{ENTER}")
win32api.Sleep(2500)
shell.SendKeys("^a") # CTRL+A may "select all" depending on which window's focused
shell.SendKeys("{DELETE}") # Delete selected text? Depends on context. :P
shell.SendKeys("{TAB}") #Press tab... to change focus or whatever
您需要 WinApi 函數 SendInput。
請參閱 MSDN 中的說明: http : //msdn.microsoft.com/en-us/library/windows/desktop/ms646310( v= vs.85).aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.