Ejemplo n.º 1
0
def startit():
    global startbtn
    startbtn.configure(bg="#3cba54", text="Select 1 point", padx=20)
    keyboard.wait('p')
    flags, hcursor, (x1, y1) = win32gui.GetCursorInfo()
    startbtn.configure(bg="#3cba54", text="Select 2 point", padx=20)
    keyboard.wait('p')
    flags, hcursor, (x2, y2) = win32gui.GetCursorInfo()
    screenshot = ImageGrab.grab(bbox=(x1, y1, x2, y2))
    screenshot.save("screenshot.png", "PNG")
    startbtn.configure(bg="#3cba54", text="Done", padx=40)
    # search fast

    def startbrowser():
        global driver
        global startbtn
        driver = webdriver.Ie(executable_path=r'C:\SeleniumDrivers\IEDriverServer.exe')
        startbtn.configure(bg="#4885ed", text="Search", padx=40)
    # mltithreading
    p1 = th.Thread(target=startbrowser)
    p1.start()
    p1.join()
    # image to text
    pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
    query = pytesseract.image_to_string('screenshot.png')
    print(query)
    # search in google
    driver.get("https://www.google.com/search?&q=" + "\"" + query + "\"")
def new_rec(end_wait=0.5):
    '''record then return a new mouse movement recording

    Keyword arguments:
    end_wait -- time mouse must stay still to signify end of recording
    '''
    actions = []  #list of actions making up recording

    start_x, start_y = wgui.GetCursorInfo()[2]
    old_pos = start_pos[:]

    start_time = None
    new_time = time.time()
    last_move_time = new_time

    while (new_time - last_move_time < end_wait  #hasn't waited for max time
           or not start_time):  #hasn't move
        new_time = time.time()
        new_pos = wgui.GetCursorInfo()[2]
        if new_pos != old_pos:

            # start recording if first move
            if (start_time == None):
                print("recording")
                start_time = new_time

            actions.append((new_pos[0] - start_x, new_pos[1] - start_y,
                            new_time - start_time))
            last_move_time = new_time
            old_pos = new_pos

    return actions
Ejemplo n.º 3
0
def find_hook():
    print("Searching hook...")
    old_mouse = win32gui.GetCursorInfo()[
        1]  # Return int of mouse icon. Will change if mouse icon change.
    for y in range(SEARCH_BOX[2], SEARCH_BOX[3], 50):
        for x in range(SEARCH_BOX[0], SEARCH_BOX[1], 60):
            mouse_pos((x, y))
            time.sleep(.05)
            current_mouse = win32gui.GetCursorInfo()[1]
            if current_mouse != old_mouse:
                print("Hook found!")
                return True
    return False
Ejemplo n.º 4
0
async def click(sizeX, sizeY):
    global clicked
    print(sizeX / sizeY)
    if sizeX / sizeY < 1.5 and clicked == False:
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,
                             win32gui.GetCursorInfo()[0],
                             win32gui.GetCursorInfo()[1], 0, 0)
        print("clicked left")
        clicked = True
    elif sizeX / sizeY > 1.5 and clicked == True:
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,
                             win32gui.GetCursorInfo()[0],
                             win32gui.GetCursorInfo()[1], 0, 0)
        print("uncliked")
        clicked = False
def human_move_to(xy, recordings=default_recordings):
    '''move to a position on screen by playing back a human mouse movement

    Keyword arguments:
    new_xy -- position to move to on screen
    recordings -- list of recordings that can be played    
    '''

    x, y = wgui.GetCursorInfo()[2]
    dx = xy[0] - x
    dy = xy[1] - y

    if not (dx == 0 and dy == 0):
        chosen_act = None
        chosen_diff = 99999999
        for ac in recordings:
            if ((ac[-1][0] > 0) == (dx > 0) and (ac[-1][1] > 0) == (dy > 0)):
                new_diff = (ac[-1][0] - dx)**2 + (ac[-1][1] - dy)**2
                if new_diff < chosen_diff:
                    chosen_act = ac
                    chosen_diff = new_diff

        #get scale
        if chosen_act[-1][0] == 0:
            x_scale = 1.5
        else:
            x_scale = dx / chosen_act[-1][0]
        if chosen_act[-1][1] == 0:
            y_scale = 1.5
        else:
            y_scale = dy / chosen_act[-1][1]

        t_scale = random.uniform(0.9, 1.1)
        perform_rec(distort_rec(chosen_act, x_scale, y_scale, t_scale), (x, y))
Ejemplo n.º 6
0
def graj():
    print("Jestesmy w grze")
    global klasy
    global niepodswietlony
    niepodswietlony = 0
    klasy = first_klasy
    zajete = []
    broken = 0
    pyautogui.moveTo(50, 50)
    time.sleep(30)
    niepodswietlony = win32gui.GetCursorInfo()[1]
    print(niepodswietlony)
    while True:
        #wywal_pierwszy()
        for _ in range(1):
            zajete = kup(zajete)
            if umieramy():
                broken = 1
                break
        if broken:
            break

        ruszaj()
        if umieramy():
            break

        lvlup()
        if umieramy():
            break

        szukaj_dwojek()
        if umieramy():
            break
Ejemplo n.º 7
0
    def trackClicks(self):
        state_left = win32api.GetKeyState(0x01)  # Left button down = 0 or 1. Button up = -127 or -128
        
        while not self.trackClickThreadTerminate:
            a = win32api.GetKeyState(0x01)
            c = win32api.GetKeyState(win32con.VK_CONTROL)

            if a != state_left:  # Button state changed
                state_left = a
                _, _, (x, y) = win32gui.GetCursorInfo()
                if a < 0 and c < 0: 
                    #process a ctrl click at pixel x, y by translating into an x/y position in the tab and checking if it is in the cell gap
                    if x > self.x + self.border and x < self.x + self.w - self.border and y > self.y + self.border and y < self.y + self.h - self.border:
                        #get the x,y position within the overlay
                        xNorm = x - self.x - self.border
                        yNorm = y - self.y - self.border

                        #check if the click falls within a cell and not in a gap
                        if xNorm % (self.boxWidth + self.cellGap) < self.w and yNorm % (self.boxHeight + self.cellGap) < self.h:
                            xCell = xNorm // (self.boxWidth + self.cellGap)
                            yCell = yNorm // (self.boxHeight + self.cellGap)

                            #remove the highlight from the clicked item
                            self.removeHighlight(xCell, yCell)

                            #pass the click off to the inventory module for processing. Let inventory worry about if there is actually an item there or not
                            if self.tabType == "QuadStash" or self.tabType == "PremiumStash" or self.tabType == "NormalStash":
                                tab = self.ui.settings.currentSettings["Chaos"]["index"]
                                self.ui.inventory.clickFromStash(tab, xCell, yCell)
Ejemplo n.º 8
0
    def _curved_move(pt, duration, resolution):

        # Any duration less than this is rounded to 0.0 to instantly move the mouse.
        pyautogui.MINIMUM_DURATION = 0  # Default: 0.1
        # Minimal number of seconds to sleep between mouse moves.
        pyautogui.MINIMUM_SLEEP = 0  # Default: 0.05
        # The number of seconds to pause after EVERY public function call.
        pyautogui.PAUSE = 0  # Default: 0.1
        cp = random.randint(3,
                            5)  # Number of control points. Must be at least 2.
        flags, hcursor, (x1, y1) = win32gui.GetCursorInfo()
        x2, y2 = pt

        # Distribute control points between start and destination evenly.
        x = np.linspace(x1, x2, num=cp, dtype='int')
        y = np.linspace(y1, y2, num=cp, dtype='int')

        # Randomise inner points a bit (+-RND at most).
        RND = 10
        xr = [random.randint(-RND, RND) for k in range(cp)]
        yr = [random.randint(-RND, RND) for k in range(cp)]
        xr[0] = yr[0] = xr[-1] = yr[-1] = 0
        x += xr
        y += yr

        # Approximate using Bezier spline.
        degree = 3 if cp > 3 else cp - 1  # Degree of b-spline. 3 is recommended.
        # Must be less than number of control points.
        tck, u = interpolate.splprep([x, y], k=degree)

        # Max size for accurate sleep for windows 60fps accuracy
        max_size = int(duration / (1 / 60))

        # Move upto a certain number of points
        size = int(Mouse._point_dist(x1, y1, x2, y2) / resolution)
        #old u = np.linspace(0, 1, num=2+int(Mouse._point_dist(x1,y1,x2,y2) / resolution))

        if size > max_size:
            size = max_size

        u = np.linspace(0, 1, num=2 + int(size))

        points = interpolate.splev(u, tck)

        # Move mouse.
        timeout = duration / len(points[0])

        point_list = list(zip(*(i.astype(int) for i in points)))

        distortPoints = Mouse.distortPoints(point_list, 1, 1, 0.5)

        tween = pytweening.easeOutQuad

        targetPoints = len(distortPoints)

        tweened_points = Mouse.tweenPoints(distortPoints, tween, targetPoints)

        for point in tweened_points:
            Mouse._move(point)
            time.sleep(timeout)
Ejemplo n.º 9
0
def click(x=None, y=None):
    if x is not None and y is not None:
        win32api.SetCursorPos((x, y))
    else:
        flags, hcursor, (x, y) = win32gui.GetCursorInfo()
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
Ejemplo n.º 10
0
 def get_cursor_ratio(self):
     cursor_info = win32gui.GetCursorInfo()[2]
     c = (cursor_info[0] * 1.25, cursor_info[1] * 1.25)
     gr = self.game_rect
     r1 = 1.0 * (c[0] - gr[0]) / (gr[2] - gr[0])
     r2 = 1.0 * (c[1] - gr[1]) / (gr[3] - gr[1])
     return r1, r2
def calibrate():
    global calibrationScreen
    global calibrationDirection
    global direction
    pressed=False
    while (calibrationScreen == False or calibrationDirection==False):
        flags, hcursor, loc = win32gui.GetCursorInfo()
        printscreen= grab_screen([0, 31, 720, 607])
        printscreen = cv2.circle(printscreen, (currentX, currentY), 1, (0, 0, 255), 5)
        if(calibrationScreen==False):
            if cv2.waitKey(25) & 0xFF == ord('q'):
                calibrationScreen=True
                print("Screen has been calibrated")
        #print(getDistancetoPoint(direction[0],direction[1],currentX,currentY))
        #print(getDistancetoPoint(loc[0],loc[1],currentX,currentY))
        printscreen = cv2.circle(printscreen, (direction[0], direction[1]), 1, (0, 255, 0 ), 5)
        if(calibrationDirection==False):
            direction[0]=loc[0]
            direction[1]=loc[1]-31
            if cv2.waitKey(25) & 0xFF == ord('w'):
                calibrationDirection = True
                print("Direction has been calibrated")

        if cv2.waitKey(25) & 0xFF == ord('k'):
            pressed=True
            init_control_gui()

        if(pressed):
            get_filters_from_panel()
            cv2.imshow('calibration_window2', HSVFILTER(printscreen))
        else:
            cv2.imshow('calibration_window', printscreen)

    cv2.destroyAllWindows()
Ejemplo n.º 12
0
def but_click_move(e):
    global mouse_flag, ptstart, pfrom
    if (mouse_flag):
        f, hc, pt = pag.GetCursorInfo()
        diff = ((pfrom.x - pt[0]), (pfrom.y - pt[1]))
        actmove = ((int(ptstart[0]) - diff[0]), (int(ptstart[1]) - diff[1]))
        nag.geometry("700x200+%d+%d" % actmove)
Ejemplo n.º 13
0
 def getMouseInfo(self):
     '''
     현재 마우스 위치 파악.
     return : MouseInfo
     '''
     mi = MouseInfo(*win32gui.GetCursorInfo())
     return mi
Ejemplo n.º 14
0
def ScreenshotByWin32API():
    hwnd = win32gui.GetDesktopWindow()
    hwndDC = win32gui.GetWindowDC(hwnd)
    mfcDC = win32ui.CreateDCFromHandle(hwndDC)
    saveDC = mfcDC.CreateCompatibleDC()
    saveBitMap = win32ui.CreateBitmap()
    w = win32print.GetDeviceCaps(hwndDC, win32con.DESKTOPHORZRES)
    h = win32print.GetDeviceCaps(hwndDC, win32con.DESKTOPVERTRES)
    saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
    saveDC.SelectObject(saveBitMap)
    saveDC.BitBlt((0, 0), (w, h), mfcDC, (0, 0), win32con.SRCCOPY)
    #add cursor
    curFlags, curH, (curX, curY) = win32gui.GetCursorInfo()
    if curH != 0:
        saveDC.DrawIcon((curX, curY), curH)
    #see https://stackoverflow.com/questions/5999007/active-window-screenshot-with-python-pil-and-windows-api-how-to-deal-with-round
    bmpinfo = saveBitMap.GetInfo()
    bmpstr = saveBitMap.GetBitmapBits(True)
    im = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']),
                          bmpstr, 'raw', 'BGRX', 0, 1)
    #release memory
    win32gui.DeleteObject(saveBitMap.GetHandle())
    saveDC.DeleteDC()
    mfcDC.DeleteDC()
    win32gui.ReleaseDC(hwnd, hwndDC)
    return im
Ejemplo n.º 15
0
 def get_current_cursor(self):
     try:
         # Get Display Context
         hwin = win32gui.GetDesktopWindow()
         hwindc = win32gui.GetWindowDC(hwin)
         srcdc = win32ui.CreateDCFromHandle(hwindc)
         memdc = srcdc.CreateCompatibleDC()
         # Create Bitmap
         bmp = win32ui.CreateBitmap()
         bmp.CreateCompatibleBitmap(srcdc, 32, 32)
         # Draw icon on Bitmap
         memdc.SelectObject(bmp)
         c = win32gui.GetCursorInfo()[1]
         memdc.DrawIcon((0, 0), c)
         # Convert Bitmap to numpy array(Image)
         signedIntsArray = bmp.GetBitmapBits(True)
         im = Image.frombuffer("RGB", (32, 32), signedIntsArray)
         #img = np.fromstring(signedIntsArray, dtype='uint8')
         #img.shape = (32,32,4)
         im = np.array(im)
         im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)
         # Release handlers
         srcdc.DeleteDC()
         memdc.DeleteDC()
         win32gui.ReleaseDC(hwin, hwindc)
         win32gui.DeleteObject(bmp.GetHandle())
         return im
     except Exception as e:
         #print("Win32Api Error:", e)
         #exc_type, exc_obj, exc_tb = os.sys.exc_info()
         #print(exc_type, exc_tb.tb_lineno)
         return self.hand_cursor_im
Ejemplo n.º 16
0
def getNormalCursorhandle():
    randomWait(300, 500)
    rm = mouseWondering(XWONDER[0], XWONDER[1], YWONDER[0], YWONDER[1],
                        DURWONDER[0], DURWONDER[1])
    pyautogui.moveRel(rm[0], rm[1], rm[2], pyautogui.easeOutQuad)
    randomWait(200, 300)
    mouseInfo = win32gui.GetCursorInfo()
    return mouseInfo[1]
Ejemplo n.º 17
0
 def PositionToMouse(self):
     shell = win32com.client.Dispatch("WScript.Shell")
     shell.SendKeys('%')
     flags, hcursor, (x, y) = win32gui.GetCursorInfo()
     win32gui.SetWindowPos(self.getHandleOfThisWindow(), win32con.HWND_TOP,
                           x - 180, y - 115, 600, 100,
                           win32con.SWP_SHOWWINDOW)
     self.makeItForeground()
Ejemplo n.º 18
0
def mouse_check():
    posX = []
    posY = []
    flags, hcursor, (x, y) = win32gui.GetCursorInfo()
    posX.append(x)
    posY.append(y)
    #print(str(x) + ' ' + str(y))
    return posX, posY
Ejemplo n.º 19
0
def click_here():
    """Click at where the cursor is

    :return: None
    """
    # TODO Add more modes to this function. Support for other clicks
    _, _, mouse_pos = win32gui.GetCursorInfo()
    ac.click(mouse_pos[0], mouse_pos[1])
Ejemplo n.º 20
0
def parse_command(data):
    if data[0] == "ping":
        if data[1] == "true":
            _, _, (x, y) = win32gui.GetCursorInfo()
            image = getRectAsImage((x - 200, y - 300, x + 200, y + 300))

            val = ""

            try:
                image.save('im.png', format='png')

                with open("im.png", "rb") as imageFile:
                    val += str(base64.b64encode(imageFile.read()))
            except OSError:
                print("failed to create image")

            return val + ";"
        else:
            return "pong;"
    elif data[0] == "mouseClick":
        amount = 1
        btn = 'left'
        for param in data:
            if param[:7] == "amount=":
                amount = param[7:]
            elif param[:4] == "btn=":
                btn = param[4:]
        WindowsControl.click(amount=amount, btn=btn)
        return "mouse click;"
    elif data[0] == "mouseMove":
        WindowsControl.move_rel(data[1], data[2])
        return "mouse moved " + data[1] + " " + data[2] + ";"
    elif data[0] == "mouseDrag":
        btn = 'left'
        if data[1]:
            btn = data[1]
        WindowsControl.drag_start(btn=btn)
        return "mouse drag start;"
    elif data[0] == "mouseDragEnd":
        btn = 'left'
        if data[1]:
            btn = data[1]
        WindowsControl.drag_end(btn=btn)
        return "mouse drag end;"
    elif data[0] == "vscroll":
        WindowsControl.vscroll_wheel(data[1])
        return "vertical scroll;"
    elif data[0] == "hscroll":
        WindowsControl.hscroll_wheel(data[1])
        return "horizontal scroll;"
    elif data[0] == "zoom":
        WindowsControl.zoom(data[1])
        return "zoom;"
    elif data[0] == "k":
        WindowsControl.keyboard_entry(data[1])
        return "keyboard: " + data[1] + ";"
    else:
        return data[0] + " is not a recognized command;"
Ejemplo n.º 21
0
def mouse_getCurrentCursorTypeName(cursorTypeNameDictionary: dict = {65561: 'IDC_APPSTARTING',
                                                                     65539: 'IDC_ARROW',
                                                                     65545: 'IDC_CROSS',
                                                                     65567: 'IDC_HAND',
                                                                     65563: 'IDC_HELP',
                                                                     65541: 'IDC_IBEAM',
                                                                     65559: 'IDC_NO',
                                                                     65557: 'IDC_SIZEALL',
                                                                     65551: 'IDC_SIZENESW',
                                                                     65555: 'IDC_SIZENS',
                                                                     65549: 'IDC_SIZENWSE',
                                                                     65553: 'IDC_SIZEWE',
                                                                     65547: 'IDC_UPARROW',
                                                                     65543: 'IDC_WAIT'}) -> str:
    try:
        return cursorTypeNameDictionary[win32gui.GetCursorInfo()[1]]
    except:
        return 'CUSTOMIDC_' + str(win32gui.GetCursorInfo()[1])
Ejemplo n.º 22
0
    def get_pixel(self):
        # '0x01' is code for left mouse button
        while True:
            if (GetAsyncKeyState(0x01) < 0): break
            time.sleep(0.01)

        _, _, (x, y) = win32gui.GetCursorInfo()
        (r, g, b) = PIL.ImageGrab.grab().load()[x, y]
        self.set_color(r, g, b)
Ejemplo n.º 23
0
def click_and_drag(x0,y0,x1,y1):
    '''(int,int,int,int) -> None
    '''
    flags, hcursor, (x,y) = win32gui.GetCursorInfo()
    SetCursorPos(x0, y0) 
    mouse_event(2, 0, 0, 0, 0) # click
    SetCursorPos(x1, y1)
    mouse_event(4, 0, 0, 0, 0) #unclick
    SetCursorPos(x, y)
Ejemplo n.º 24
0
def smooth_move(autohotpy, x, y):
    flags, hcursor, (startX, startY) = win32gui.GetCursorInfo()
    coordinates = draw_line(startX, startY, x, y)
    x = 0
    for dot in coordinates:
        x += 1
        if x % 2 == 0 and x % 3 == 0:
            time.sleep(0.005)
        autohotpy.moveMouseToPosition(dot[0], dot[1])
Ejemplo n.º 25
0
 def getCursorType():
     """返回当前鼠标图标类型
     
     :rtype: MouseCursorType
     """
     hcursor = win32gui.GetCursorInfo()[1]
     for key, flag in _cursor_flags.items():
         if win32gui.LoadCursor(0, flag) == hcursor:
             return key
     return None
Ejemplo n.º 26
0
def add_mouse(img, w):
    img = bytearray(img)
    flags, hcursor, (cx,cy) = win32gui.GetCursorInfo()
    cursor = get_cursor(hcursor)
    cursor_mean = cursor.mean(-1)
    where = np.where(cursor_mean>0)
    for x, y in zip(where[0], where[1]):
        rgb = [x for x in cursor[x,y]]
        img = set_pixel(img, w, x+cy, y+cx, rgb=rgb)
    return img
Ejemplo n.º 27
0
    def fish_grid(self):
        if self.dead_UI:
            exit()
        self.UI.log_viewer.emitter.emit("Throwing bait...")
        self.throw_bait()

        grid_step = 20
        found = False
        bait_coords = None

        a = int(self.frame[1] + self.frame[3] * self.grid_frac_ver[0])
        b = int(self.frame[1] + self.frame[3] * self.grid_frac_ver[1])
        c = int(self.frame[0] + self.frame[2] * self.grid_frac_hor[0])
        d = int(self.frame[0] + self.frame[2] * self.grid_frac_hor[1])

        for j in range(a, b, grid_step):
            if found:
                break
            for i in range(c, d, grid_step):
                precursor = win32gui.GetCursorInfo()[1]
                utils.move_mouse([i, j])
                time.sleep(0.02)
                postcursor = win32gui.GetCursorInfo()[1]
                if precursor != postcursor:
                    found = True
                    j += int(self.frame[2] / 100)
                    pyautogui.moveRel(0,
                                      int(self.frame[2] / 100),
                                      duration=0.05)

                    self.UI.log_viewer.emitter.emit(
                        "Found bait at coordinates {0} , {1}".format(i, j))

                    bait_coords = [i, j]
                    break
        if bait_coords is not None:
            self.watch_bait(bait_coords)

        self.tries += 1
        self.UI.tries_count_label.text_emitter.emit("{} tries".format(
            str(self.tries)))
        self.jump()
Ejemplo n.º 28
0
    def submit(self, instance, root_path):
        flags, hcursor, (x, y) = win32gui.GetCursorInfo()
        self.update_session_info()
        self.submit_to_broswer()
        move_mouse_to(x, y, with_click=False)


# SingleHwnd(19860206).activate()
# time.sleep(1)
# SingleHwnd(win32gui.GetForegroundWindow()).get_title()
# rect = win32gui.GetWindowRect(19860206)
Ejemplo n.º 29
0
 def PositionToMouse(self, width, height):
     shell = win32com.client.Dispatch("WScript.Shell")
     shell.SendKeys('%')
     flags, hcursor, (x, y) = win32gui.GetCursorInfo()
     print("height is " + str(
         funktionDieNenStringNimmtUndSieGibtZurueckAnzahlZeilenInAbhaengigkeitDerZeilenbreite(
             self.outTxt.text, 100)) + 'lines')
     win32gui.SetWindowPos(self.getHandleOfThisWindow(), win32con.HWND_TOP,
                           round(x - width / 2), y - height - 80, width,
                           height, win32con.SWP_SHOWWINDOW)
     self.makeItForeground()
Ejemplo n.º 30
0
 def read_cursor_position(self):
     '''
         reads the cursor position and retrieve its color
     '''
     while self.running:
         time.sleep(0.001)
         hdc = win32gui.GetDC(0)
         flags, hcursor, (x, y) = win32gui.GetCursorInfo()
         color = win32gui.GetPixel(hdc, x, y)
         color = self.rgb_int_to_hex(color)
         self.color_queue.put(color)