用AutoItLibrary進行鍵盤操作

syfly007發表於2013-02-17

用autoIt對應的python庫AutoItLibrary操作鍵盤很方便,記錄一下,備忘。模擬Ctrl+f的操作,使windows Media Player自動播放下一首歌曲
from win32con import *
from win32com.client import Dispatch
  
def enter_game():
    AutoItX = Dispatch( "AutoItX3.Control" )
    # Block All Input
    AutoItX.BlockInput( 1 )
    AutoItX.WinActivate( 'Windows Media Player','')
    AutoItX.Send( "{CTRLDOWN}b{CTRLUP}" )
    AutoItX.Send( "{LWINDOWN}{DOWN}{LWINUP}" )
    # Unblock input
    AutoItX.BlockInput( 0 )


if __name__ == "__main__":
    #mouse_event (MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 )
    next_music()


相關文章