autopy這個包可以直接操作電腦的一些行為,比如點擊,移動鼠標啥的,但是可能只使用於windows,用處有限,不過做個簡單的游戲輔助還是可以的。
網上資料賊少,很多不能用的,現總結一些可以用的放在這:
import autopy autopy.alert.alert('hello') autopy.mouse.move(100,100) autopy.mouse.smooth_move(400,400) print(autopy.mouse.location()) width,height = autopy.screen.size() print(width,height) a = autopy.bitmap.capture_screen().get_color(1,1) b = autopy.screen.get_color(1,1) autopy.bitmap.capture_screen().save('lfsenior.png') autopy.mouse.click() autopy.mouse.toggle(None,True) autopy.mouse.toggle(None,False) autopy.mouse.toggle(down=True,button=None) autopy.mouse.toggle(True) def where_is_the_rubbish(): '''查找回收站在屏幕中的位置''' rubbish=autopy.bitmap.Bitmap.open('rubbish.png') screen=autopy.bitmap.capture_screen() pos=screen.find_bitmap(rubbish) if pos: print ('找到了,他的位置在:%s' % str(pos)) else: print ('沒有找到') where_is_the_rubbish()
目前成功的代碼,右鍵不知道怎點擊,找了圈沒找到。
補,右鍵點擊
autopy.mouse.click(autopy.mouse.Button.RIGHT)