def set_window(): click_count = 0 state_left = win32api.GetKeyState(0x01) # Default mouse state # Checks for left click while True: a = win32api.GetKeyState(0x01) if a != state_left: # Button state changed state_left = a # If left mouse is clicked if a < 0: # First click if click_count == 0: # Stores mouse position firstX, firstY = win32api.GetCursorPos() print('Top Left Corner Selected: ', firstX, firstY) click_count = click_count + 1 # Second click elif click_count == 1: secondX, secondY = win32api.GetCursorPos() print('Bottom Right Corner Selected: ', secondX, secondY) click_count = click_count + 1 break # Finds width and height of area clicked width, height = abs(firstX - secondX), abs(firstY - secondY) # Creates a namedtuple() to store play area dimensions Dimensions = namedtuple('dimensions', ['x', 'y', 'w', 'h']) dims = Dimensions(firstX, firstY, width, height) return dims
def mouse(): current = win32api.GetCursorPos() cx = lead_x = int(current[0]) cy = lead_y = int(current[1]) last = time.time() while(True): if (ser.inWaiting()>0): xx=ser.readline() xx=int(xx.decode()) #print(xx) if win32api.GetAsyncKeyState(ord('X')): sys.exit() elif xx == 77: lead_x=lead_x+3 elif xx == 33: lead_x=lead_x-3 elif xx == 88: lead_y=lead_y-3 elif xx == 22: lead_y=lead_y+3 elif xx == 66: p=win32api.GetCursorPos() lclick(p[0],p[1]) elif xx == 11: p=win32api.GetCursorPos() rclick(p[0],p[1]) elif xx == 1: print("Cursor lost its control") return() #sys.exit() win32api.SetCursorPos((lead_x,lead_y)) time.sleep(0.001)
def getCoords(): x, y = win32api.GetCursorPos() x = x - x_pad y = y - y_pad print(x, y) tupler = (x, y) return tupler
def move_windows(windows: dict): cursor = win32api.GetCursorPos() # Since we will be iterating multiple times through monitors, we need to listify the generator monitors = list(get_display_info()) active_monitor = None for monitor in monitors: if are_rect_intersecting(monitor["Monitor"], cursor): active_monitor = monitor break moved = [] for hwnd, state in windows.items(): if not are_rect_intersecting(active_monitor["Monitor"], state[-1]): class_name = win32gui.GetClassName(hwnd) try: move_window(hwnd, state, monitors, active_monitor) moved.append(class_name) except Exception as e: kenny.warning('Unable to move window(s) ["%s"]', class_name) else: kenny.debug("Skipping, window already in active_monitor") if len(moved) > 0: kenny.info("Moved %s window(s) to active_monitor", moved)
def get_cords(): x,y = win32.GetCursorPos() x = x - x_pad y = y - y_pad print(x,y)
def main(): # assign state to mouse button clicks state_left = win32api.GetKeyState( 0x01) # Left button down = 0 or 1. Button up = -127 or -128 state_right = win32api.GetKeyState( 0x02) # Right button down = 0 or 1. Button up = -127 or -128 # initialize size of matrix cells = 8 # adjust darkness to screenshot for color calibration darkness = .18 # initialize matrices Matrix = [[0 for i in range(cells)] for j in range(cells)] # user #comment out after readme file created #### print("left click at top left corner of jewel field, hold, and release at bottom right corner of jewel field") # loop for setting area of matrix while True: a = win32api.GetKeyState(0x01) b = win32api.GetKeyState(0x02) if a != state_left: # Button state changed state_left = a if a < 0: x1, y1 = win32api.GetCursorPos() else: x2, y2 = win32api.GetCursorPos() w = x2 - x1 h = y2 - y1 cellWidth = w / cells cellHeight = h / cells break time.sleep(0.01) while True: visualMatrix = [[0 for i in range(cells)] for j in range(cells)] # screenshot board im = pyautogui.screenshot(region=(x1, y1, w, h)) # darken image by 10% im = im.point(lambda x: x * (1 - darkness)) # get median rgb value of part of each cell for i in range(cells): for j in range(cells): box = (i * cellWidth + (cellWidth * (2 / 7)), j * cellHeight + (cellHeight * (2 / 7)), i * cellWidth + cellWidth - (cellWidth * (2 / 7)), j * cellHeight + cellHeight - (cellHeight * (2 / 7))) region = im.crop(box) Matrix[j][i] = ImageStat.Stat(region).median # convert median rgb to primary color rgb or char representation for i in range(cells): for j in range(cells): visualMatrix[j][i] = convert_to_primary(Matrix[j][i]) ## break ## Debug breaker t = Tree(visualMatrix) t.children = [] t = createTree(visualMatrix, cells, t) t.setList() t.children.sort() ## break ## Debug breaker # click away counter = 0 for child in t.children: if counter > 4: break clck1 = child.c1 clck2 = child.c2 pyautogui.moveTo(x1 + int(clck1[1] * cellWidth + cellWidth / 2), y1 + int(clck1[0] * cellHeight + cellHeight / 2)) time.sleep(.01) pyautogui.click() pyautogui.moveTo(x1 + int(clck2[1] * cellWidth + cellWidth / 2), y1 + int(clck2[0] * cellHeight + cellHeight / 2)) time.sleep(.01) pyautogui.click() counter += 1
def main(): # assign state to mouse button clicks state_left = win32api.GetKeyState( 0x01) # Left button down = 0 or 1. Button up = -127 or -128 state_right = win32api.GetKeyState( 0x02) # Right button down = 0 or 1. Button up = -127 or -128 # get square size of matrix #### cells = int(input("Input Matrix Square Size: ")) #### darkness = float(input("percent darkened .xx format: ")) cells = 8 darkness = .18 # initialize matrices Matrix = [[0 for i in range(cells)] for j in range(cells)] rgbMatrix = [[0 for i in range(cells)] for j in range(cells)] visualMatrix = [[0 for i in range(cells)] for j in range(cells)] # user #comment out after readme file created #### print("left click at top left corner of jewel field, hold, and release at bottom right corner of jewel field") # loop for setting area of matrix while True: a = win32api.GetKeyState(0x01) b = win32api.GetKeyState(0x02) if a != state_left: # Button state changed state_left = a if a < 0: x1, y1 = win32api.GetCursorPos() else: x2, y2 = win32api.GetCursorPos() w = x2 - x1 h = y2 - y1 cellWidth = w / cells cellHeight = h / cells break time.sleep(0.001) tk = Tk() canvas = Canvas(tk, width=w + 2, height=h + 2) tk.geometry("%dx%d+1100+150" % (w + 2, h + 2)) tk.title("RGB Color Tile") canvas.pack() while True: # screenshot board im = pyautogui.screenshot(region=(x1, y1, w, h)) # darken image by 10% im = im.point(lambda x: x * (1 - darkness)) # get median rgb value of part of each cell for i in range(cells): for j in range(cells): box = (i * cellWidth + (cellWidth * (2 / 7)), j * cellHeight + (cellHeight * (2 / 7)), i * cellWidth + cellWidth - (cellWidth * (2 / 7)), j * cellHeight + cellHeight - (cellHeight * (2 / 7))) region = im.crop(box) Matrix[j][i] = ImageStat.Stat(region).median # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html ## Matrix[j][i] = ImageStat.Stat(region.quantize(8,0,0,)).mean ## for i in range(cells): ## print(Matrix[i]) # convert median rgb to primary color rgb or char representation for i in range(cells): for j in range(cells): rgbMatrix[j][i] = convert_to_primary(Matrix[j][i], 'rgb') visualMatrix[j][i] = convert_to_primary(Matrix[j][i], 'vis') ## break # create visual canvas # TODO make a command line option later for i in range(cells): for j in range(cells): canvas.create_rectangle(i * cellWidth, j * cellHeight, i * cellWidth + cellWidth, j * cellHeight + cellHeight, fill='#%02x%02x%02x' % rgbMatrix[j][i]) tk.update() ## time.sleep(0.05) ## break ## Debug breaker q = MyPriorityQueue() for i in range(cells): for j in range(1, cells): copy = [row[:] for row in visualMatrix] copy = swapCellsHoriz(i, j, j - 1, copy) coords, matches = findMatches(copy, cells) if matches > 0: #q.put(coords,-matches) q.put([[i, j], [i, j - 1]], -matches) print(coords) copy = [row[:] for row in visualMatrix] copy = swapCellsVert(i, j, j - 1, copy) coords, matches = findMatches(copy, cells) if matches > 0: #q.put(coords,-matches) q.put([[j, i], [j - 1, i]], -matches) print(coords) for i in range(cells): print(visualMatrix[i]) print("") #go through priority queue of moves and click ## while q.len() > 0: for i in range(5): ## print(q.get()) if (q.len() == 0): time.sleep(.2) break clck1, clck2 = q.get() ## print(clck1) ## print(clck2) pyautogui.moveTo(x1 + int(clck1[1] * cellWidth + cellWidth / 2), y1 + int(clck1[0] * cellHeight + cellHeight / 2)) time.sleep(.001) pyautogui.click() pyautogui.moveTo(x1 + int(clck2[1] * cellWidth + cellWidth / 2), y1 + int(clck2[0] * cellHeight + cellHeight / 2)) time.sleep(.001) pyautogui.click() time.sleep(.001)