def handle_cancelling_sell(runescape_window, ge_slot, list_of_items_in_use):
# click box 2
box_2_loc = pointfrombox.random_point((runescape_window.bottom_right_corner[0]-254, runescape_window.bottom_right_corner[1]-165), (runescape_window.bottom_right_corner[0]-224, runescape_window.bottom_right_corner[1]-139))
realmouse.move_mouse_to(box_2_loc[0], box_2_loc[1])
pyautogui.click()
# runescape_window.update_money(runescape_window.money+((ge_slot.item.quantity_to_buy-2)*ge_slot.item.price_instant_sold_at)) think this line is breaking it
# click collect box 1
box_1_loc = pointfrombox.random_point((runescape_window.bottom_right_corner[0]-303, runescape_window.bottom_right_corner[1]-164), (runescape_window.bottom_right_corner[0]-273, runescape_window.bottom_right_corner[1]-139))
realmouse.move_mouse_to(box_1_loc[0], box_1_loc[1])
pyautogui.click()
# if not then click box 2 and proceed to sell the item
wait_for('Tools/screenshots/lent_item_box.png', runescape_window)
if ge_slot.item.number_available_to_buy > 0:
find_up_to_date_sell_price(runescape_window, ge_slot)
ge_slot.item.set_price_instant_bought_at(ge_slot.item.price_instant_bought_at-1)
else:
ge_slot.item.set_price_instant_bought_at(int(ge_slot.item.price_instant_bought_at*0.98)-1)
sell_items(runescape_window, ge_slot)
# item didnt buy any of so we can just mark this slot as open and start again
python类click()的实例源码
def wait_for(image, runescape_window):
# adding a possible failsafe in here
time_entered = time.time()
# could add a failsafe in here incase we misclick or something, this
# should be something to come back to
failsafe_count = 0
while(True):
found = pyautogui.locateOnScreen(image, region=(runescape_window.top_left_corner[0], runescape_window.top_left_corner[1], runescape_window.bottom_right_corner[
0] - runescape_window.top_left_corner[0], runescape_window.bottom_right_corner[1] - runescape_window.top_left_corner[1]))
if found != None:
break
elif failsafe_count > 10:
print("We can't seem to fix the problem so the script is now aborting")
quit()
elif time.time()-time_entered > 5 :
failsafe_count += 1
print('We appear to be stuck so attempting to move the mouse and see if this fixes it')
#print('For debug:')
#print(runescape_window.bottom_right_corner[0], runescape_window.top_left_corner[0])
#print(runescape_window.bottom_right_corner[1], runescape_window.top_left_corner[1])
realmouse.move_mouse_to(random.randint(runescape_window.top_left_corner[0], runescape_window.bottom_right_corner[0]), random.randint(runescape_window.top_left_corner[1], runescape_window.bottom_right_corner[1]))
#pyautogui.click()
time_entered = time.time()
def prevent_logout(top_left_corner, bottom_right_corner, runescape_window):
seed = random.random()
x, y = pyautogui.size()
if seed > 0.5: # opens up the sale history tab for 5 seconds then returns to ge tab
while(True):
realmouse.move_mouse_to(random.randint(0,x), random.randint(0,y))
if len(list(pyautogui.locateAllOnScreen('Tools/screenshots/sale_history_button.png', region=(top_left_corner[0], top_left_corner[1], bottom_right_corner[0]-top_left_corner[0], bottom_right_corner[1]-top_left_corner[1]))))>0:
move_mouse_to_box('Tools/screenshots/sale_history_button.png', top_left_corner, bottom_right_corner)
pyautogui.click()
time.sleep(9*random.random()+1)
move_mouse_to_box('Tools/screenshots/grand_exchange_button.png', top_left_corner, bottom_right_corner)
pyautogui.click()
break
else: # examines the money pouch
examine_money(bottom_right_corner)
# pass in an image and a search region
def basic_api():
x, y = pg.size()
print x, y
'''
pg.moveTo(300,300,2)
pg.moveTo(300,400,2)
pg.moveTo(500,400,2)
pg.moveTo(500,300,2)
pg.moveTo(300,300,2)
#pg.moveTo(300,500,2)
'''
# pg.click(100,100)
word = [u'??', u'???']
pos = [452, 321]
pg.moveTo(pos[0], pos[1])
pg.click()
pg.typewrite(word[0])
def example():
screenWidth, screenHeight = pg.size()
currentMouseX, currentMouseY = pg.position()
pg.moveTo(500, 550)
pg.click()
pg.moveRel(None, 10) # move mouse 10 pixels down
pg.doubleClick()
# pg.moveTo(500, 500, duration=2, tween=pyautogui.tweens.easeInOutQuad) # use tweening/easing function to move mouse over 2 seconds.
pg.typewrite('Hello world!', interval=0.25) # type with quarter-second pause in between each key
pg.press('esc')
pg.keyDown('shift')
pg.press(['left', 'left', 'left', 'left', 'left', 'left'])
pg.keyUp('shift')
pg.hotkey('ctrl', 'c')
delta_y = 50
def applyChain(file):
p = subprocess.Popen(["audacity", "./{}".format(file)])
time.sleep(7)
try:
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/discard.png'))
time.sleep(1)
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/yes.png'))
except:
pass
time.sleep(1)
if len(list(pyautogui.locateAllOnScreen('src/images/audacity_fileButton.png'))) > 1:
pyautogui.keyDown('alt')
pyautogui.press('f10')
pyautogui.keyUp('alt')
time.sleep(1)
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_fileButton.png'))
time.sleep(2)
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_applyChain.png'))
time.sleep(2)
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_applyToCurrentFile.png'))
time.sleep(10)
p.terminate()
print('Done')
def setCursorPos( yc, pyp):
yp = np.zeros(2)
if abs(yc[0]-pyp[0])<5 and abs(yc[1]-pyp[1])<5:
yp[0] = yc[0] + .7*(pyp[0]-yc[0])
yp[1] = yc[1] + .7*(pyp[1]-yc[1])
else:
yp[0] = yc[0] + .1*(pyp[0]-yc[0])
yp[1] = yc[1] + .1*(pyp[1]-yc[1])
return yp
# Depending upon the relative positions of the three centroids, this function chooses whether
# the user desires free movement of cursor, left click, right click or dragging
def __init__(self, n_button_clicks=2, loopquit=None):
"""Create handler that records click events.
loopquit must be set to some callable which will quit main loop.
n_button_clicks is the maximum number of *left* clicks that
will be recorded.
Hitting Escape or the right mouse button will break out of loop
self.output stores events and is a dict of lists.
The keys of self.output are eventtypes in Gdk.EventType
e.g., button_rel_events = self.output[Gdk.EventType.BUTTON_RELEASE]
"""
self.n_button_clicks = n_button_clicks
evtype_to_cb = {
BUTTON_RELEASE: self.handler_button_rel,
KEY_RELEASE: self.handler_key,
}
super().__init__(evtype_to_cb, loopquit)
def _process_select(self, screen):
self.move_to(0, 0)
time.sleep(0.1)
for i in reversed(range(8)):
position = self.find_image_center(screen, self.images['stage'], 70 + i % 4 * 130, 180 + i / 4 * 170, 80, 20)
if position != None and (i == 0 or random.randint(0, 1) == 0):
x, y = position
self.move_to(x, y + 10)
time.sleep(0.1)
self.click()
time.sleep(2)
break
position = self.find_image_center(screen, self.images['select_title'], 10, 16, 60, 40)
if position == None:
self.state = self.STATE_PLAY
return (None, False)
return (None, False)
def _process_result(self, screen):
self.move_to(0, 0)
time.sleep(0.1)
position = self.find_image_center(screen, self.images['select'], 460, 406, 60, 40)
if position != None:
x, y = position
self.move_to(x, y)
time.sleep(0.1)
self.click()
time.sleep(3)
else:
x, y = 410, 425
self.move_to(x, y)
time.sleep(0.1)
self.click()
time.sleep(3)
position = self.find_image_center(screen, self.images['select_title'], 10, 16, 60, 40)
if position != None:
self.state = self.STATE_SELECT
return (None, False)
def on_command_move(self, mouse_command=None):
try:
if mouse_command is not None:
mouse_command = mouse_command.strip() # remove the extra white spaces
mouse_command = mouse_command.lower() # Converts into lower Strings
if mouse_command == "left":
self.move_left() # move left function is called
elif mouse_command == "right":
self.move_right() # move right function is called
elif mouse_command == "up":
self.move_up() # move up function is called
elif mouse_command == "down":
self.move_down() # Move down function called
elif mouse_command == "click":
self.on_click_screen() # Clicks the specified location in the Screen
else:
print("Invalid Command Mate!")
return # Returns to the Place where the function was called
except KeyboardInterrupt as Ex:
print("Interrupted by the Keyboard keys :", Ex)
except Exception as Ex:
print("The following Error Occurred", Ex) # this is the Printing of the exception
def test_check(self):
for i in range(2):
pyautogui.moveTo(100, 100, duration=0.25)
pyautogui.moveTo(200, 100, duration=0.25)
pyautogui.moveTo(200, 200, duration=0.25)
pyautogui.moveTo(100, 200, duration=0.25)
# M_obj = MouseMove()
# M_obj.move_left()
# M_obj.move_up()
# M_obj.move_right()
# M_obj.move_down()
# M_obj.test_check() # Just for the debuggin purpose
# M_obj.on_command_move("left")
# M_obj.on_command_move("up")
# M_obj.on_command_move("right")
# M_obj.on_command_move("down")
# M_obj.on_command_move("click")
# M_obj.scroll_down()
def handle_cancelling_buy(runescape_window, ge_slot, list_of_items_in_use):
# click box 1
box_1_loc = pointfrombox.random_point((runescape_window.bottom_right_corner[0]-303, runescape_window.bottom_right_corner[1]-164), (runescape_window.bottom_right_corner[0]-273, runescape_window.bottom_right_corner[1]-139))
realmouse.move_mouse_to(box_1_loc[0], box_1_loc[1])
pyautogui.click()
# runescape_window.update_money(runescape_window.money+((ge_slot.item.quantity_to_buy-2)*ge_slot.item.price_instant_sold_at)) think this line is breaking it
# wait and check if we have jumped back to the main window, handle this
time.sleep(3)
if not len(list(pyautogui.locateAllOnScreen('Tools/screenshots/lent_item_box.png', region=(runescape_window.top_left_corner[0], runescape_window.top_left_corner[1], runescape_window.bottom_right_corner[0]-runescape_window.top_left_corner[0], runescape_window.bottom_right_corner[1]-runescape_window.top_left_corner[1])))) > 0:
# we have to click box 2 still so click it and handle it
box_2_loc = pointfrombox.random_point((runescape_window.bottom_right_corner[0]-254, runescape_window.bottom_right_corner[1]-165), (runescape_window.bottom_right_corner[0]-224, runescape_window.bottom_right_corner[1]-139))
realmouse.move_mouse_to(box_2_loc[0], box_2_loc[1])
pyautogui.click()
# if not then click box 2 and proceed to sell the item
wait_for('Tools/screenshots/lent_item_box.png', runescape_window)
if ge_slot.item.number_available_to_buy > 0:
find_up_to_date_sell_price(runescape_window, ge_slot)
ge_slot.item.set_price_instant_bought_at(ge_slot.item.price_instant_bought_at-1)
sell_items(runescape_window, ge_slot, record_number_selling=True)
runescape_window.add_to_items_on_cooldown(ge_slot.item)
ge_slot.item.update_number_available_to_buy(ge_slot.item.number_available_to_buy-ge_slot.item.quantity_to_buy)
return()
# item didnt buy any of so we can just mark this slot as open and start again
runescape_window.update_money(runescape_window.money+((ge_slot.item.quantity_to_buy-2)*ge_slot.item.price_instant_sold_at))
ge_slot.update_buy_or_sell_state(None)
list_of_items_in_use.remove(ge_slot.item.item_name)
ge_slot.item.set_price_instant_bought_at(None)
ge_slot.item.set_price_instant_sold_at(None)
ge_slot.set_item_in_ge_slot(None)
def cancel_offer(top_left_corner, bottom_right_corner, runescape_window):
loc_of_ge_point = pointfrombox.random_point(top_left_corner, bottom_right_corner)
realmouse.move_mouse_to(loc_of_ge_point[0], loc_of_ge_point[1])
pyautogui.click()
# print('now waiting and then trying to locate x button')
# wait_for('Tools/screenshots/abort_x_button.png', runescape_window)
time.sleep(3+random.random())
fail_count = 0
# print('We are about to cancel an offer that we believe to be in the window with coords {}, we are at line 497'.format(runescape_window.bottom_right_corner))
while True:
cancel_loc = pyautogui.locateOnScreen('Tools/screenshots/abort_x_button.png', region=(runescape_window.top_left_corner[0], runescape_window.top_left_corner[1], runescape_window.bottom_right_corner[0]-runescape_window.top_left_corner[0], runescape_window.bottom_right_corner[1]-runescape_window.top_left_corner[1]))
if fail_count > 3:
print('failed 3 times so trying to locate the abort button from the inventory collect button')
to_inv_loc = pyautogui.locateOnScreen('Tools/screenshots/to_inv_button.png', region=(runescape_window.top_left_corner[0], runescape_window.top_left_corner[1], runescape_window.bottom_right_corner[0]-runescape_window.top_left_corner[0], runescape_window.bottom_right_corner[1]-runescape_window.top_left_corner[1]))
cancel_loc = tuple(numpy.subtract(to_inv_loc, (163, 107, 163, 8)))
if cancel_loc == None:
print('Failed to locate the abort button {} times, trying again in 5 seconds'.format(fail_count))
time.sleep(5)
fail_count += 1
else:
break
# print('we have saved the location of the x button ready to click')
# print(cancel_loc)
point_of_cancel_button = pointfrombox.random_point((cancel_loc[0], cancel_loc[1]), (cancel_loc[0]+cancel_loc[2], cancel_loc[1]+cancel_loc[3]))
realmouse.move_mouse_to(point_of_cancel_button[0], point_of_cancel_button[1])
pyautogui.click()
def collect_items_from_ge_slot(ge_slot, runescape_window):
point_to_click = pointfrombox.random_point(ge_slot.top_left_corner, ge_slot.bottom_right_corner)
realmouse.move_mouse_to(point_to_click[0], point_to_click[1])
pyautogui.click()
wait_for('Tools/screenshots/completed_offer_page.png', runescape_window)
point_of_item_collection_box_1 = pointfrombox.random_point((runescape_window.bottom_right_corner[0] - 303, runescape_window.bottom_right_corner[
1] - 166), (runescape_window.bottom_right_corner[0] - 273, runescape_window.bottom_right_corner[1] - 138))
point_of_item_collection_box_2 = pointfrombox.random_point((runescape_window.bottom_right_corner[0] - 254, runescape_window.bottom_right_corner[
1] - 166), (runescape_window.bottom_right_corner[0] - 222, runescape_window.bottom_right_corner[1] - 138))
realmouse.move_mouse_to(point_of_item_collection_box_2[0], point_of_item_collection_box_2[1])
pyautogui.click()
realmouse.move_mouse_to(point_of_item_collection_box_1[0], point_of_item_collection_box_1[1])
pyautogui.click()
wait_for('Tools/screenshots/lent_item_box.png', runescape_window)
def examine_money(position):
# this whole block just examines the amount of money
point = pointfrombox.random_point((138, 94), (189, 109))
# that the account has just for auto log out purposes
money_pouch = (position[0] - point[0], position[1] - point[1])
# so that it has a recording of the last time an action
realmouse.move_mouse_to(money_pouch[0], money_pouch[1])
# was taken and can keep track of this value in future to stop logouts
# occuring
pyautogui.click(button='right')
point = pointfrombox.random_point((-75, -32), (74, -24))
examine = (money_pouch[0] - point[0], money_pouch[1] - point[1])
realmouse.move_mouse_to(examine[0], examine[1])
pyautogui.click()
def click():
gui.click()
#print 'click'
def clickFile():
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_fileButton.png'))
def clickApplyChain():
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_applyChain.png'))
def clickApplyToFile():
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_applyToCurrentFile.png'))
def maxWindow():
try:
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/discard.png'))
time.sleep(1)
pyautogui.click(pyautogui.locateCenterOnScreen('src/images/yes.png'))
except:
pass
time.sleep(1)
if len(list(pyautogui.locateAllOnScreen('src/images/audacity_fileButton.png'))) > 1:
pyautogui.keyDown('alt')
pyautogui.press('f10')
pyautogui.keyUp('alt')
def open_firefox():
# Printing basic message
msg(1,'Opening Firefox...')
# Location the start button
_start_button_=pyautogui.locateOnScreen('images/start_button.png')
_location_=pyautogui.center(_start_button_)
# Clicking the start button
if not pyautogui.click(_location_):
msg(1,'Opened start menu successfully!')
else:
msg(3,'Failed to open start menu!')
ext()
time.sleep(1)
# Search for Firefox in the menu search
pyautogui.typewrite('firefox')
pyautogui.typewrite('\n')
# Print message
msg(1,'Firefox is now open and running.')
# Function used to locate GMail
def locate_gmail():
#Sleep for a while and wait for Firefox to open
time.sleep(2)
# Printing message
msg(1,'Opening Gmail...')
# Typing the website on the browser
pyautogui.keyDown('ctrlleft'); pyautogui.typewrite('a'); pyautogui.keyUp('ctrlleft')
pyautogui.typewrite('https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F<mpl=default')
pyautogui.typewrite('\n')
# Wait for a while until the website responds
time.sleep(3)
# Print a simple message
msg(1,'Locating the form...')
# Locate the form
_gmail_=pyautogui.locateOnScreen('images/gmail_form.png')
_form_=pyautogui.center(_gmail_)
# Check and print message
if not pyautogui.click(_form_):
msg(1,'Located the form.')
else:
msg(3,'Failed to locate the form.')
ext()
# Function used to randomize credentials
def chooseAction(yp, rc, bc):
out = np.array(['move', 'false'])
if rc[0]!=-1 and bc[0]!=-1:
if distance(yp,rc)<50 and distance(yp,bc)<50 and distance(rc,bc)<50 :
out[0] = 'drag'
out[1] = 'true'
# print 'dragging'
return out
elif distance(rc,bc)<40:
out[0] = 'left'
# print 'left click'
return out
elif distance(yp,rc)<40:
out[0] = 'right'
# print 'right click'
return out
else:
# print 'moving'
return out
else:
out[0] = -1
return out
# Movement of cursor on screen, left click, right click and dragging actions are performed here
def setCursorPos( yc, pyp):
yp = np.zeros(2)
if abs(yc[0]-pyp[0])<5 and abs(yc[1]-pyp[1])<5:
yp[0] = yc[0] + .7*(pyp[0]-yc[0])
yp[1] = yc[1] + .7*(pyp[1]-yc[1])
else:
yp[0] = yc[0] + .1*(pyp[0]-yc[0])
yp[1] = yc[1] + .1*(pyp[1]-yc[1])
return yp
# Depending upon the relative positions of the three centroids, this function chooses whether
# the user desires free movement of cursor, left click, right click or dragging
def chooseAction(yp, rc, bc):
out = np.array(['move', 'false'])
if rc[0]!=-1 and bc[0]!=-1:
if distance(yp,rc)<50 and distance(yp,bc)<50 and distance(rc,bc)<50 :
out[0] = 'drag'
out[1] = 'true'
# print 'dragging'
return out
elif distance(rc,bc)<40:
out[0] = 'left'
# print 'left click'
return out
elif distance(yp,rc)<40:
out[0] = 'right'
# print 'right click'
return out
else:
# print 'moving'
return out
else:
out[0] = -1
return out
# Movement of cursor on screen, left click, right click and dragging actions are performed here
def performAction( yp, rc, bc, perform):
if perform :
cursor[0] = 4*(yp[0]-110)
cursor[1] = 4*(yp[1]-120)
if yp[0]>110 and yp[0]<590 and yp[1]>120 and yp[1]<390:
pyautogui.moveTo(cursor[0],cursor[1])
elif yp[0]<110 and yp[1]>120 and yp[1]<390:
pyautogui.moveTo( 8 , cursor[1])
elif yp[0]>590 and yp[1]>120 and yp[1]<390:
pyautogui.moveTo(1912, cursor[1])
elif yp[0]>110 and yp[0]<590 and yp[1]<120:
pyautogui.moveTo(cursor[0] , 8)
elif yp[0]>110 and yp[0]<590 and yp[1]>390:
pyautogui.moveTo(cursor[0] , 1072)
elif yp[0]<110 and yp[1]<120:
pyautogui.moveTo(8, 8)
elif yp[0]<110 and yp[1]>390:
pyautogui.moveTo(8, 1072)
elif yp[0]>590 and yp[1]>390:
pyautogui.moveTo(1912, 1072)
else:
pyautogui.moveTo(1912, 8)
if rc[0]!=-1 and bc[0]!=-1:
if abs(rc[0]-bc[0])<35 and abs(rc[1]-bc[1])<20:
pyautogui.click(button = 'left')
def chooseAction(yp, rc, bc):
out = np.array(['move', 'false'])
if rc[0]!=-1 and bc[0]!=-1:
if distance(yp,rc)<50 and distance(yp,bc)<50 and distance(rc,bc)<50 :
out[0] = 'drag'
out[1] = 'true'
return out
elif distance(rc,bc)<40:
out[0] = 'left'
return out
elif distance(yp,rc)<40:
out[0] = 'right'
return out
elif distance(yp,rc)>40 and rc[1]-bc[1]>120:
out[0] = 'down'
return out
elif bc[1]-rc[1]>110:
out[0] = 'up'
return out
else:
return out
else:
out[0] = -1
return out
# Movement of cursor on screen, left click, right click,scroll up, scroll down
# and dragging actions are performed here based on value stored in 'action'.
def setCursorPos( yc, pyp):
yp = np.zeros(2)
if abs(yc[0]-pyp[0])<5 and abs(yc[1]-pyp[1])<5:
yp[0] = yc[0] + .7*(pyp[0]-yc[0])
yp[1] = yc[1] + .7*(pyp[1]-yc[1])
else:
yp[0] = yc[0] + .1*(pyp[0]-yc[0])
yp[1] = yc[1] + .1*(pyp[1]-yc[1])
return yp
# Depending upon the relative positions of the three centroids, this function chooses whether
# the user desires free movement of cursor, left click, right click or dragging
def chooseAction(yp, rc, bc, actionHistory):
out = np.array(['move', 'false'])
if rc[0]!=-1 and bc[0]!=-1:
if not leftHand and checkActionHistory( actionHistory, 'ONOFF'):
if bc[0]-yp[0]>130 and bc[1]-yp[1]>170 and bc[1]-rc[1]<40:
out[0] = 'ONOFF'
return out
elif leftHand and checkActionHistory( actionHistory, 'ONOFF'):
if yp[0]-bc[0]>130 and bc[1]-yp[1]>170 and bc[1]-rc[1]<40:
out[0] = 'ONOFF'
return out
if distance(yp,rc)<50 and distance(yp,bc)<50 and distance(rc,bc)<50 :
out[0] = 'drag'
out[1] = 'true'
return out
elif distance(rc,bc)<40:
out[0] = 'left'
return out
elif distance(yp,rc)<40 and checkActionHistory( actionHistory, 'right'):
out[0] = 'right'
return out
elif distance(yp,rc)>40 and rc[1]-bc[1]>120:
out[0] = 'down'
return out
elif bc[1]-rc[1]>110:
out[0] = 'up'
return out
else:
return out
else:
out[0] = -1
return out
# Movement of cursor on screen, left click, right click,scroll up, scroll down
# and dragging actions are performed here based on value stored in 'action'.