import snp
snp.get_float()
回傳一個浮點數, 例如 3.14
, -0.000001
, 123.456
snp.get_int()
回傳一個整數, 例如 2147
, -101
snp.get_str()
回傳一個字串, snp2018
, 140.113.0.1
# file: test.py
import snp
f = snp.get_float();
print(f)
i = snp.get_int();
print(i)
s = snp.get_str();
print(s)
執行範例 1
3.14
3.14
134
134
snp2018
snp2018
執行範例 2
1.2.3 1.99
Not float. Please try again
1.99
0x123 abcd 1000
Not int. Please try again
Not int. Please try again
1000
HI
HI
snp.locateOnScreen(image)
(left,top,w,h)
表示在螢幕上找到的 image 的位置還有 image 寬與高None
import snp
import pyautogui
p = snp.locateOnScreen('dino.png')
if p != None:
pyautogui.click(p[0]+p[2]//2,p[1]+p[3]//2)
snp.locateCenterOnScreen(image)
(x,y)
表示在螢幕上找到的 image 的中心位置,None
import snp
import pyautogui
p = snp.locateCenterOnScreen('dino.png')
if p != None:
pyautogui.click(p[0],p[1])
snp.locateAllOnScreen(image)
import snp
import pyautogui
for p in snp.locateAllOnScreen('dino.png'):
x, y = p[0]+p[2]//2, p[1]+p[3]//2
pyautogui.click(x,y)
snp.setScale( r )
import snp
snp.setScale(2) # for Mac retina
snp.locateCenterOnScreen(image, threshold=0.9)
表示相似度要在 0.9 以上的匹配才會被回傳snp.locateCenterOnScreen(image, region(100,100,50,100))
表示只會截圖 (100,100) 到 (150,200) 為對角線的矩形範圍threshold
表示相似度百分比的門檻,預設為 0.87
region
表示要截圖的範圍,以 (left,top,w,h)
表示,預設為(0,0,600,200)
,愈大的截圖範圍,截圖頻率會越低,不建議截一半螢幕大小以上的面積。