python模拟键盘输入的问题

这是一段自动登录QQ的代码,我感觉是def an()出了问题,但是我看不出问题在哪儿。

import subprocess
import win32api
import win32con
import time

from ctypes import *

qq_exe = r"D:\qq\Bin\QQ.exe"
subprocess.Popen([qq_exe])      #打开QQ
time.sleep(5)

windll.user32.SetCursorPos(969, 583)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)      #点击账号输入框
time.sleep(0.5)

def an(qq):
    for i in qq:
        #print(i)
        win32api.keybd_event(ord(i),0,0,0) 
        win32api.keybd_event(ord(i),0,win32con.KEYEVENIF_KEYUP,0)
        time.sleep(0.5)

an("********")      #输入账号

win32api.keybd_event(9,0,0,0)
win32api.keybd_event(9,0,win32con.KEYEVENIF_KEYUP,0)    #Tab

an("**********")    #输入密码
win32api.keybd_event(13,0,0,0)
win32api.keybd_event(13,0,win32con.KEYEVENIF_KEYUP,0)

错误提示是

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\dakai QQ.py", line 25, in <module>
    an("********")
  File "C:\Users\Administrator\Desktop\dakai QQ.py", line 22, in an
    win32api.keybd_event(ord(i),0,win32con.KEYEVENIF_KEYUP,0)
AttributeError: 'module' object has no attribute 'KEYEVENIF_KEYUP'

谁可以告诉我知道问题在哪儿?怎么解决。

查看回复