安装:终端输入指令 pip3 install pyautogui
执行之后依赖库很多一起安装。
Successfully installed PyTweening-1.0.4 mouseinfo-0.1.3 pyautogui-0.9.53 pygetwindow-0.0.9 pymsgbox-1.0.9 pyobjc-8.3 pyobjc-core-8.3 pyobjc-framework-AVFoundation-8.3 pyobjc-framework-AVKit-8.3 pyobjc-framework-Accessibility-8.3 pyobjc-framework-Accounts-8.3 pyobjc-framework-AdServices-8.3 pyobjc-framework-AdSupport-8.3
pyobjc-framework-AddressBook-8.3 pyobjc-framework-AppTrackingTransparency-8.3 pyobjc-framework-AppleScriptKit-8.3 pyobjc-framework-AppleScriptObjC-8.3 pyobjc-framework-ApplicationServices-8.3 pyobjc-framework-AudioVideoBridging-8.3 pyobjc-framework-AuthenticationServices-8.3 pyobjc-framework-AutomaticAssessmentConfiguration-8.3 pyobjc-framework-Automator-8.3 pyobjc-framework-BusinessChat-8.3 pyobjc-framework-CFNetwork-8.3
pyobjc-framework-CalendarStore-8.3 pyobjc-framework-CallKit-8.3 pyobjc-framework-ClassKit-8.3 pyobjc-framework-CloudKit-8.3 pyobjc-framework-Cocoa-8.3 pyobjc-framework-Collaboration-8.3 pyobjc-framework-ColorSync-8.3 pyobjc-framework-Contacts-8.3 pyobjc-framework-ContactsUI-8.3 pyobjc-framework-CoreAudio-8.3 pyobjc-framework-CoreAudioKit-8.3 pyobjc-framework-CoreBluetooth-8.3 pyobjc-framework-CoreData-8.3 pyobjc-framework-CoreHaptics-8.3
pyobjc-framework-CoreLocation-8.3 pyobjc-framework-CoreMIDI-8.3 pyobjc-framework-CoreML-8.3 pyobjc-framework-CoreMedia-8.3 pyobjc-framework-CoreMediaIO-8.3 pyobjc-framework-CoreMotion-8.3 pyobjc-framework-CoreServices-8.3 pyobjc-framework-CoreSpotlight-8.3 pyobjc-framework-CoreText-8.3 pyobjc-framework-CoreWLAN-8.3
pyobjc-framework-CryptoTokenKit-8.3 pyobjc-framework-DVDPlayback-8.3 pyobjc-framework-DeviceCheck-8.3 pyobjc-framework-DictionaryServices-8.3 pyobjc-framework-DiscRecording-8.3 pyobjc-framework-DiscRecordingUI-8.3
pyobjc-framework-DiskArbitration-8.3 pyobjc-framework-EventKit-8.3
pyobjc-framework-ExceptionHandling-8.3 pyobjc-framework-ExecutionPolicy-8.3 pyobjc-framework-ExternalAccessory-8.3 pyobjc-framework-FSEvents-8.3 pyobjc-framework-FileProvider-8.3 pyobjc-framework-FileProviderUI-8.3 pyobjc-framework-FinderSync-8.3 pyobjc-framework-GameCenter-8.3 pyobjc-framework-GameController-8.3 pyobjc-framework-GameKit-8.3 pyobjc-framework-GameplayKit-8.3 pyobjc-framework-IMServicePlugIn-8.3 pyobjc-framework-IOSurface-8.3 pyobjc-framework-ImageCaptureCore-8.3 pyobjc-framework-InputMethodKit-8.3 pyobjc-framework-InstallerPlugins-8.3 pyobjc-framework-InstantMessage-8.3 pyobjc-framework-Intents-8.3 pyobjc-framework-KernelManagement-8.3 pyobjc-framework-LatentSemanticMapping-8.3 pyobjc-framework-LaunchServices-8.3 pyobjc-framework-LinkPresentation-8.3 pyobjc-framework-LocalAuthentication-8.3 pyobjc-framework-MLCompute-8.3 pyobjc-framework-MapKit-8.3 pyobjc-framework-MediaAccessibility-8.3 pyobjc-framework-MediaLibrary-8.3 pyobjc-framework-MediaPlayer-8.3 pyobjc-framework-MediaToolbox-8.3 pyobjc-framework-Metal-8.3 pyobjc-framework-MetalKit-8.3 pyobjc-framework-MetalPerformanceShaders-8.3 pyobjc-framework-MetalPerformanceShadersGraph-8.3 pyobjc-framework-ModelIO-8.3 pyobjc-framework-MultipeerConnectivity-8.3 pyobjc-framework-NaturalLanguage-8.3 pyobjc-framework-NetFS-8.3 pyobjc-framework-Network-8.3 pyobjc-framework-NetworkExtension-8.3 pyobjc-framework-NotificationCenter-8.3 pyobjc-framework-OSAKit-8.3 pyobjc-framework-OSLog-8.3 pyobjc-framework-OpenDirectory-8.3 pyobjc-framework-PassKit-8.3 pyobjc-framework-PencilKit-8.3 pyobjc-framework-Photos-8.3 pyobjc-framework-PhotosUI-8.3
pyobjc-framework-PreferencePanes-8.3 pyobjc-framework-PushKit-8.3 pyobjc-framework-Quartz-8.3 pyobjc-framework-QuickLookThumbnailing-8.3
pyobjc-framework-ReplayKit-8.3 pyobjc-framework-SafariServices-8.3 pyobjc-framework-SceneKit-8.3 pyobjc-framework-ScreenSaver-8.3 pyobjc-framework-ScreenTime-8.3 pyobjc-framework-ScriptingBridge-8.3
pyobjc-framework-SearchKit-8.3 pyobjc-framework-Security-8.3 pyobjc-framework-SecurityFoundation-8.3 pyobjc-framework-SecurityInterface-8.3 pyobjc-framework-ServiceManagement-8.3 pyobjc-framework-Social-8.3 pyobjc-framework-SoundAnalysis-8.3 pyobjc-framework-Speech-8.3 pyobjc-framework-SpriteKit-8.3 pyobjc-framework-StoreKit-8.3 pyobjc-framework-SyncServices-8.3 pyobjc-framework-SystemConfiguration-8.3 pyobjc-framework-SystemExtensions-8.3
pyobjc-framework-UniformTypeIdentifiers-8.3
pyobjc-framework-UserNotifications-8.3 pyobjc-framework-UserNotificationsUI-8.3
pyobjc-framework-VideoSubscriberAccount-8.3 pyobjc-framework-VideoToolbox-8.3 pyobjc-framework-Virtualization-8.3 pyobjc-framework-Vision-8.3 pyobjc-framework-WebKit-8.3 pyobjc-framework-iTunesLibrary-8.3 pyobjc-framework-libdispatch-8.3 pyperclip-1.8.2
pyrect-0.1.4 pyscreeze-0.1.28 rubicon-objc-0.4.2
简单应用:
import pyautogui
print(pyautogui.size()) # 分辨率
print(pyautogui.position()) #当前鼠标位置
print(pyautogui.onScreen(100,3833)) #当前坐标点是否在屏幕上可见
截图:
截取全屏幕
img=pyautogui.screenshot() img.save("img.png")
鼠标点击功能: 单击,双击都正常
m_print("双击")
pyautogui.doubleClick(0, 11, button=pyautogui.LEFT, duration=2)
pyautogui.doubleClick(0, 11, button=pyautogui.RIGHT, duration=1)
m_print("单击")
pyautogui.click(100, 10, clicks=1, interval=1, button=pyautogui.PRIMARY, duration=1)
pyautogui.click(100, 100, clicks=1, interval=1, button=pyautogui.PRIMARY, duration=1)
m_print("3击")
# pyautogui.tripleClick(300,300,button=pyautogui.LEFT,duration=2)
pyautogui.tripleClick(x=500, y=270, interval=0.0, button='left', duration=0.0, tween=pyautogui.linear)
3击报错:
Traceback (most recent call last):
File "/Users/gdlocal/Documents/Python/practice/pyautoguipra/simpapipra.py", line 28, in <module>
pyautogui.tripleClick(x=500, y=270, interval=0.0, button='left', duration=0.0, tween=pyautogui.linear)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyautogui/__init__.py", line 598, in wrapper
returnVal = wrappedFunction(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyautogui/__init__.py", line 1162, in tripleClick
_logScreenshot(logScreenshot, "click", "%s,3,%s,%s" % (x, y), folder=".")
TypeError: not enough arguments for format string
格式化少了一个值,随便传了duration进去。能运行,但是三击效果暂时无法检验。
图像识别:
result = pyautogui.locateOnScreen("headerpic.png")
print(result)
匹配结果总是: None ,百度说要加上confidence,但是执行时候报错,
result = pyautogui.locateOnScreen("headerpic.png",confidence=0.9)
print(result)
The confidence keyword argument is only available if OpenCV is installed.
安装: pip3 install opencv-python -i https://pypi.douban.com/simple
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/101631.html