Skip to content
Snippets Groups Projects
Commit 1f121394 authored by Cool Fire's avatar Cool Fire
Browse files

Add script to detect by threshold and script to get mouse pos.

parent 41b66d09
Branches master
No related tags found
No related merge requests found
{
"outputloc": [100, 100],
"outputloc": [1480, 800],
"outputtext": "test",
"grabs": [
[100,100,20],
[200,200,20],
[300,300,20]
[1335, 870, 20],
[1260, 210, 20],
[1370, 360, 20],
[820, 315, 20],
[1301, 501, 20],
[525, 187, 20],
[861, 510, 20],
[434, 826, 20]
]
}
#!/usr/bin/env python2
from PIL import ImageChops
from pyscreenshot import grab
from time import sleep
import json
import pyautogui
# Load config
with open('config.json') as c:
conf = json.load(c)
# Calculate box coordinates from x, y and radius
boxes = []
for g in conf['grabs']:
boxes.append( (g[0]-g[2], g[1]-g[2], g[0]+g[2], g[1]+g[2]) )
# Grab starting images to compare
source = []
for i, b in enumerate(boxes):
source.append(grab(bbox=b).convert('RGB'))
#source[i].show() # Useful for debugging box locations
# Main loop
while True:
dest = []
sleep(1)
for i, b in enumerate(boxes):
dest.append(grab(bbox=b).convert('RGB'))
#dest.append(ImageChops.difference(tmp, source[i]))
#diff.append(dest[i].getbbox())
# Write output if diffs are detected
for i, d in enumerate(dest):
diff = ImageChops.difference(source[i], dest[i])
hist = diff.histogram()
dico = len(filter(lambda a: a != 0, hist))
print str(i) + ":" + str(dico)
if dico > 100:
pyautogui.click(conf['outputloc'][0], conf['outputloc'][1])
pyautogui.typewrite(conf['outputtext'])
print 'I have done the deed!'
exit(0)
#!/usr/bin/env python2
import pyautogui
print pyautogui.position()
......@@ -3,8 +3,8 @@
from pyscreenshot import grab
loc = [700, 200]
im = grab(bbox=(loc[0]-50, loc[1]-50, loc[0]+50, loc[1]+50))
loc = [434, 826]
r = 20
im = grab(bbox=(loc[0]-r, loc[1]-r, loc[0]+r, loc[1]+r))
im.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment