0

尝试运行此脚本:

import pythoncom, pyHook 

def OnMouseEvent(event):
    # called when mouse events are received
    print 'MessageName:',event.MessageName
    print 'Message:',event.Message
    print 'Time:',event.Time
    print 'Window:',event.Window
    print 'WindowName:',event.WindowName
    print 'Position:',event.Position
    print 'Wheel:',event.Wheel
    print 'Injected:',event.Injected
    print '---'

    # return True to pass the event to other handlers
    return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.MouseAll = OnMouseEvent
# set the hook
hm.HookMouse()
# wait forever
pythoncom.PumpMessages()

我收到一个错误:

Traceback (most recent call last):
  File "C:\Python26\Test\click.py", line 1, in <module>
    import pythoncom, pyHook
  File "C:\Python26\Test\pythoncom.py", line 13, in <module>
    pythoncom.PumpMessages() #will wait forever
AttributeError: 'module' object has no attribute 'PumpMessages'

这很奇怪,因为在 shell 中导入 pythoncom 并编写命令 pythoncom.PumpMessages() 后,它运行没有任何问题。这个问题怎么可能解决?

4

1 回答 1

4

看起来你pythoncom.py在那个文件夹中有一个文件,它被导入而不是真正的 pythoncom 模块。尝试将该文件重命名为其他文件,然后运行click.py​​.

于 2011-11-21T00:14:33.853 回答