可以,需要第三方扩展。
import pyHookimport pythoncom
def onclick(event):
print event.Position
return True
hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(onclick)
hm.HookMouse()
pythoncom.PumpMessages()
hm.UnhookMouse()
Python也能象按键精灵一样模拟键鼠操作,直接用Python来做吧,该模块叫pyautogui,了解一下。
import pyautoguiprint('Press Ctrl-C to quit.')
try:
while True:
# Get and print the mouse coordinates.
x, y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(positionStr, end='')
print('\b' * len(positionStr), end='', flush=True)
except KeyboardInterrupt:
print('\nDone.')
这是Automate_the_Boring_Stuff一书中的演示代码,用于查找当前鼠标的坐标。