Example #1
0
def connected(client, uri):
    try:
        print('Client connected.')
        yield from client.send('%dx%d' % size)

        while client.open:
            data_future = asyncio.Future()
            data_futures.add(data_future)
            data = yield from data_future
            data_futures.remove(data_future)
            if not client.open: break
            yield from client.send(data)
            if not client.open: break
            data = yield from client.recv()
            if type(data) == str:
                cmd = data[0]
                pos = map(int, data[1:].split(','))
                if cmd == 'd':
                    mouse.down(*pos)
                elif cmd == 'm':
                    mouse.move(*pos)
                elif cmd == 'u':
                    mouse.up(*pos)


        print('Client disconnected.')
    except:
        print(traceback.format_exc())
Example #2
0
  def movePiece(self, move):
    print 'moving ', move.src, ' to ', move.des
    offset = self.tile_w / 2

    srcXpos = self.x + ( move.src['x'] * self.tile_w) + offset
    srcYpos = self.y + ( move.src['y'] * self.tile_h) + offset

    desXpos = self.x + ( move.des['x'] * self.tile_w) + offset
    desYpos = self.y + ( move.des['y'] * self.tile_h) + offset

    mouse.click(srcXpos, srcYpos)
    mouse.click(desXpos, desYpos)
    mouse.move(self.x - 100, self.y)
Example #3
0
def main():

# Initiate mouser class and variables
    m = Mouser()
    hold = False
    righthold = False
    middlehold = False
    
# Define shutdown process, all pins go to 0
    def shutdown():
        for i in range(9):
            m.c[i].go_to(0,205)
            sleep(15)
    
    while True:
 
# Initiate serial reading, move pin 4 after done 
        if m.ser.inWaiting()>0:
            byte = m.ser.read()
            m.c.update(byte)
            if not m.init_done and byte[0]==128:
                m.c[4].go_to(23,205)
                m.init_done = True
            
# Define button 7 as move mouse down
        if m.c[7].button==1:
            m.c[7].set_color((254,0,0))
            old_pos = mouse.getpos()
            new_pos = (old_pos[0],(old_pos[1]+5))
            mouse.move(new_pos[0],new_pos[1])
            
# Define button 1 as move mouse up
        if m.c[1].button==1:
            m.c[1].set_color((254,0,0))
            old_pos = mouse.getpos()
            new_pos = (old_pos[0],(old_pos[1]-5))
            mouse.move(new_pos[0],new_pos[1])
        
# Define button 3 as move mouse left        
        if m.c[3].button==1:
            m.c[3].set_color((254,0,0))
            old_pos = mouse.getpos()
            new_pos = (old_pos[0]-5,(old_pos[1]))
            mouse.move(new_pos[0],new_pos[1])

# Define button 5 as move mouse right
        if m.c[5].button==1:
            m.c[5].set_color((254,0,0))
            old_pos = mouse.getpos()
            new_pos = (old_pos[0]+5,(old_pos[1]))
            mouse.move(new_pos[0],new_pos[1])
           
# Define shutdown as holding buttons 6 and 8 for 5 seconds       
        if m.c[6].press_seconds()>4 and m.c[8].press_seconds()>4:
            shutdown()
            break

    sleep(0.01)
Example #4
0
    def do_POST(self):
        """
        Handles the POST requests

        Arguments:
        - self: The main object pointer.
        """
        contentLength = self.headers.getheader('content-length')
        if contentLength:
            contentLength = int(contentLength)
            inputBody = self.rfile.read(contentLength)

            if inputBody.startswith("move:"):
                X, Y = inputBody[5:].split(",")
                debug.info( "mouseTrap.httpd", "Moving mouse to %s,%s" % (X, Y) )
                mouse.move(int(X), int(Y))
                self.send_response(200, 'OK')
        else:
            print( "mal" )
Example #5
0
def mouse_up(lp):
    mouse.move(0, -sense, False, 0)
Example #6
0
 def SubProcedure_MousePointDiff(self,data):
     pos = mouse.get_position()
     mouse.move(pos[0] + int(data[0]), pos[1] + int(data[1]))
     if len(data)>2:
         time.sleep(float(data[2])/1000)
     return 1
Example #7
0
# Joystick controlled mouse
# By Shubham Santosh
# last edited 12/11/2020
import mouse, sys
import time 
import serial

mouse.FAILSAFE=False
ArduinoSerial=serial.Serial('COM4',9600)  #Specify the correct COM port
time.sleep(1)                             #delay of 1 second

while 1:
   data=str(ArduinoSerial.readline().decode('ascii'))   #read the data
   (x,y,z)=data.split(":")           # assigns to x,y and z
   (X,Y)=mouse.get_position()        #read the cursor's current position
   (x,y)=(int(x),int(y))                           #convert to int
   mouse.move(X+x,Y-y)           #move cursor to desired position
   if '1' in z:                        # read the Status of SW
      mouse.click(button="left")    # clicks left button
     
print("Macro Çalıştırıldı")
if aktifmi:
    print("Açık")
else:
    print("Kapalı")

son_durum = False
while True:
    aktif_ise = is_pressed(tuş)
    if aktif_ise != son_durum:
        son_durum = aktif_ise
        if son_durum:
            aktifmi = not aktifmi
            if aktifmi:
                print("Açık")
            else:
                print("Kapalı")

    if fare_basili() and aktifmi:
        while True:
            if fare_basili() and aktifmi:
                move(kordinatlarX[xy],
                     kordinatlarY[xy],
                     absolute=False,
                     duration=gecikme)
                xy += 1
                if len(kordinatlarX) == xy:
                    xy = 0
            else:
                xy = 0
#vlc media player
vlcInstance = vlc.Instance()
media = vlcInstance.media_new('/home/pi/code/' + VIDEO_NAME)

# Create new instance of vlc player
vlcPlayer = vlcInstance.media_player_new()
vlcPlayer.stop()

# Pass pygame window id to vlc player, so it can render its contents there.
win_id = pygame.display.get_wm_info()['window']
vlcPlayer.set_xwindow(win_id)
vlcPlayer.set_media(media)
i = 0
r_acc = 0
mouse.move(IMAGE_WIDTH, IMAGE_HEIGHT, True, 0)

# WARM Up the distance sensor
for i in range(20):
    r_val = readadc(R_SENSOR_ID)
    r_sensor_value = getDistance(filter(r_val))
    print("warming up distance sensor... {}".format(r_sensor_value))
    time.sleep(0.0125)
print("Finish warm up phase")

while True:
    pygame.mouse.set_cursor((8, 8), (0, 0), (0, 0, 0, 0, 0, 0, 0, 0),
                            (0, 0, 0, 0, 0, 0, 0, 0))
    try:
        if areThereNewInputsDevices():
            sp.Popen('sudo pkill -9 -f python3 && sudo pkill -9 -f aplay',
Example #10
0
import mouse

mouse.move()
Example #11
0
def changeSize(size):
    px = mouse.get_position()[0]
    py = mouse.get_position()[1]
    size = int(size)
    if (size == 1):
        mouse.move(447, 78)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
        time.sleep(0.1)
        mouse.move(488, 148)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif (size == 2):
        mouse.move(447, 78)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
        time.sleep(0.1)
        mouse.move(482, 188)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif (size == 3):
        mouse.move(447, 78)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
        time.sleep(0.1)
        mouse.move(478, 225)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif (size == 4):
        mouse.move(447, 78)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
        time.sleep(0.1)
        mouse.move(481, 265)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    else:
        raise Exception('Size invalid')

    mouse.move(px, py)
Example #12
0
icon_market = [1176, 161]
start_drag = [1200, 200]
end_drag = [1200, 900]
button_ad = [1089, 334]
icon_items = [734, 85]
icon_crates = [1146, 959]
icon_crate = [950, 578]
reset_esc = [965, 712]
count = 0

while True:
    count += 1

    #click dell'icona della pagina principale e attesa che la pubblicità finisca
    mouse.move(icon_market)
    mouse.click()
    time.wait(1)
    mouse.drag(start_drag, end_drag, duration=1)
    mouse.move(button_ad)
    mouse.click()
    time.wait(60)

    #visione della pubblicità e ritorno alla schermata iniziale
    for i in range(5):
        keyboard.press_and_release('esc')
        time.wait(1)
    mouse.move(reset_esc)
    mouse.click()
    time.wait(1)
Example #13
0
 def returnMouseBack(self, e):
     mouse.move(self.m_x, self.m_y, absolute=True)
Example #14
0
    executable_path=
    "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
browser.maximize_window()
dates = []
browser.get('https://pangu.songshuai.com/#/login')
sleep(1)
user = browser.find_element_by_xpath("//input[@type='text']").send_keys(
    '13764110015')
sleep(1)
pwd = browser.find_element_by_xpath("//input[@type='Password']").send_keys(
    'wlh57362376')
sleep(1)
sub = browser.find_element_by_xpath("//button[@type='button']/span[1]").click()
sleep(5)
# ghc = browser.find_element_by_xpath("//span[@title='公海池']").click()
move(64, 444)
click()
sleep(3)

move(464, 379)
click()
sleep(3)

login_moble = re.search(r'<!---->1(.*?)</div>', browser.page_source).group(0)
login_0 = login_moble.replace('<!---->', '').replace('</div>', '')
print(login_0)
# dates.append(moble_1)
move(459, 431)
click()
sleep(2)
login_moble_1 = re.search(r'<!---->1(.*?)</div>', browser.page_source).group(0)
Example #15
0
import mouse
import time
import random

ms = Controller()
posX, posY = py.size()
x, y = 0, 0

safeCPU = False

wait = time.sleep
sec = 60

while True:
    x = x + 10
    if x > posX:
        x = 0
        y = y + 3
    if y > posY:
        y = 0
    colour = ps.pixelMatchesColor(x, y, (0, 230, 203))
    if colour == True:
        mouse.move(x, y, True, 0)
        ms.click(Button.left, 1)
        wait(5)
        mouse.move(0, 0, True, 0)
        safeCPU = True
    if safeCPU == True:
        wait(sec * 8)
    safeCPU = False
Example #16
0
def mouse_down(lp):
    mouse.move(0, sense, False, 0)
Example #17
0
    def Op(key, op, ox, oy):
        # print(key, op, ox, oy)
        if key == 1:
            if op == 100:

                # 左键按下
                mouse.move(ox, oy)
                mouse.press(button=mouse.LEFT)
            elif op == 117:

                # 左键弹起
                x, y = mouse.get_position()
                if ox != x or oy != y:
                    if not mouse.is_pressed():
                        mouse.press(button=mouse.LEFT)
                    mouse.move(ox, oy)
                mouse.release(button=mouse.LEFT)
        elif key == 2:

            # 滚轮事件
            if op == 0:
                # 向上
                mouse.move(ox, oy)
                mouse.wheel(delta=-1)
            else:
                # 向下
                mouse.move(ox, oy)
                mouse.wheel(delta=1)

        elif key == 3:
            # 鼠标右键
            if op == 100:
                # 右键按下
                mouse.move(ox, oy)
                mouse.press(button=mouse.RIGHT)
            elif op == 117:
                # 右键弹起
                mouse.move(ox, oy)
                mouse.release(button=mouse.RIGHT)

        else:
            k = official_virtual_keys.get(key)
            if k is not None:
                if op == 100:  # 按键按下
                    keyboard.press(k)
                elif op == 117:  # 按键抬起
                    keyboard.release(k)
Example #18
0
#!/usr/bin/python3

#run this as sudo

import time, mouse, random, os

min = 0
max = 255
deltaTime = 9 * 60

#os.system("sleep " + str(deltaTime2) + "m; poweroff")
if input("sleep? (y/n):") == "y":
    deltaTime2 = input("minutes: ")
    os.spawnl(os.P_NOWAIT, "/usr/bin/sleepoff", "sleepoff", str(deltaTime2))

print("sleep scope passed")

while True:
    mouse.move(random.randint(min, max), random.randint(min, max))
    time.sleep(deltaTime)
Example #19
0
            tan8 = math.fabs((m2 - m1) / (1 + m1 * m2))
            angle = math.atan(tan8) * 180 / math.pi
            ############################################################

            #angle = math.atan2(y2 - y1, x2 - x1) * 180.0 / math.pi;
            length = math.sqrt(math.pow((y2 - y1), 2) + math.pow((x2 - x1), 2))
            #print(angle);

            if length < 50:
                continue

            ################### get original pixel location #############

            x = sx - ((topmost[0] - 50) * sx / (w - 340))
            y = (topmost[1] * sy / (h - 281))
            mouse.move(sx - x, y, absolute=True, duration=.1)

            cv2.putText(roi, str('%d,%d' % (sx - x, y)), topmost,
                        cv2.FONT_HERSHEY_SIMPLEX, .5, (255, 255, 255), 1,
                        cv2.LINE_AA)
            #################### Clicking the mouse ########################
            if angle < 15:
                mouse.click(button='left')
                # uncomment to activate the left click
                print('left clicked')
                pass
            else:
                pass

    except:
        pass
Example #20
0
def move(x=None, y=None, absolute=True, duration=0):
    mouse.move(x, y, absolute, duration)
Example #21
0
def colorChangeAgain(pcolor):
    px = mouse.get_position()[0]
    py = mouse.get_position()[1]

    if pcolor == 0:
        mouse.move(641, 68)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif pcolor == 1:
        mouse.move(662, 68)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif pcolor == 2:
        mouse.move(685, 68)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif pcolor == 3:
        mouse.move(705, 68)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif pcolor == 4:
        mouse.move(729, 68)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif pcolor == 5:
        mouse.move(773, 68)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif pcolor == 6:
        mouse.move(572, 68)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    elif pcolor == 7:
        mouse.move(572, 85)
        time.sleep(0.1)
        mouse.press(button='left')
        time.sleep(0.1)
        mouse.release(button='left')
    else:
        raise Exception('Color invalid')

    mouse.move(px, py)
Example #22
0
is_bot_pressing = False
time_current = time()
time_before_up_click = 0
time_before_down_click = time() + clicks_down[0][1]

while i < repeats and not finish:

    if keyboard.is_pressed('ESCAPE'):
        finish = True
        break

    if time() > time_before_down_click and k < clicks_down.__len__():
        if not is_bot_pressing:
            is_bot_pressing = True
            time_before_up_click = time() + clicks_up[k][1]
            mouse.move(clicks_down[k][0][0], clicks_down[k][0][1], True)
            mouse.press()
        elif is_bot_pressing and time() >= time_before_up_click:
            is_bot_pressing = False
            if k < clicks_down.__len__() - 1:
                time_before_down_click = time() + clicks_down[k + 1][1]
            mouse.move(clicks_up[k][0][0], clicks_up[k][0][1], True)
            mouse.release()
            k += 1

    # print("time: {}, next: {}".format(time_current, time_before_down_click))

    elif k >= clicks_up.__len__():
        k = 0
        i += 1
        time_current = time()
Example #23
0
def enter_race():
    # enter a race
    keyboard.send("ctrl+alt+i")
    mouse.move(200, 600)
Example #24
0
 def focus(self):
     old_coord = mouse.get_position()
     self.current.set_focus()
     mouse.move(*old_coord)
     self.gasp()
Example #25
0
 def SubProcedure_MouseMoveTo(self,data):
     mouse.move(self.Points[int(data[0])][0],self.Points[int(data[0])][1])
     if len(data)>1:
         time.sleep(float(data[1])/1000)
     return 1
Example #26
0
port = "COM14"

ard = 0

try:
    ard = serial.Serial(port, 9600)
except Exception:
    ard = serial.Serial("COM3", 9600)

while (1):
    a = ard.readline().decode()

    cur = a.split("\t")
    cur[0] = int(cur[0])
    cur[1] = int(cur[1])
    cur[2] = int(cur[2][:-2])

    k = mouse.get_position()

    mouse.move(k[0] - cur[0] / 100, k[1] - cur[1] / 100)

    if (cur[2] == 2):
        mouse.click(button='left')
    elif (cur[2] == 1):
        mouse.click(button='right')
    #elif(cur[2]==3):
    #	mouse.double_click()
    #print(mouse.get_position())

    sleep(0.001)
def mainForTraining():
    import pygamestuff
    crosshair = pygamestuff.Crosshair([7, 2], quadratic=False)
    vc = cv2.VideoCapture(0)  # Initialize the default camera
    if vc.isOpened():  # try to get the first frame
        (readSuccessful, frame) = vc.read()
    else:
        raise (Exception("failed to open camera."))
        return

    MAX_SAMPLES_TO_RECORD = 999999
    count = 0
    recordedEvents = 0
    HT = None
    try:
        while readSuccessful and recordedEvents < MAX_SAMPLES_TO_RECORD and not crosshair.userWantsToQuit:
            pupilOffsetXYList = getOffset(frame, allowDebugDisplay=False)
            if pupilOffsetXYList is not None:  #If we got eyes, check for a click. Else, wait until we do.
                if crosshair.pollForClick():
                    crosshair.clearEvents()
                    #print( (xOffset,yOffset) )
                    #do learning here, to relate xOffset and yOffset to screenX,screenY
                    crosshair.record(pupilOffsetXYList)
                    print "recorded something"
                    crosshair.remove()
                    recordedEvents += 1
                    if recordedEvents > RANSAC_MIN_INLIERS:
                        ##                    HT = fitTransformation(np.array(crosshair.result))
                        resultXYpxpy = np.array(crosshair.result)
                        features = getFeatures(resultXYpxpy[:, :-2])
                        featuresAndLabels = np.concatenate(
                            (features, resultXYpxpy[:, -2:]), axis=1)
                        HT = RANSACFitTransformation(featuresAndLabels)
                        print HT
                if HT is not None:  # draw predicted eye position
                    currentFeatures = getFeatures(
                        np.array((pupilOffsetXYList[0], pupilOffsetXYList[1])))
                    gazeCoords = currentFeatures.dot(HT)
                    crosshair.drawCrossAt((gazeCoords[0, 0], gazeCoords[0, 1]))
                    mouse.move(gazeCoords[0, 0],
                               gazeCoords[0, 1],
                               absolute=True,
                               duration=0)
                    print gazeCoords[0, 0], "   ", gazeCoords[0, 1]
                    count += 1
            readSuccessful, frame = vc.read()
            cv2.resize(frame, (0, 0), fx=0.2, fy=0.2)
            cv2.imshow('Face', frame)

        print "writing"
        crosshair.write()  #writes data to a csv for MATLAB
        crosshair.close()
        print "HT:\n"
        print HT
        resultXYpxpy = np.array(crosshair.result)
        print "eyeData:\n"
        print getFeatures(resultXYpxpy[:, :-2])
        print "resultXYpxpy:\n"
        print resultXYpxpy[:, -2:]
    finally:
        vc.release()  #close the camera
Example #28
0
def mouse_right(lp):
    mouse.move(sense, 0, False, 0)
Example #29
0
 try:
     data = json.loads(str(msg))
 except Exception:
     socket.send("{state:false}")
     continue
 if not data.has_key("action"):
     socket.send("{state:false}")
     continue
 action = data["action"]
 detail = data["data"]
 if action == "warp":
     print "warp", int(detail["x"]), int(detail["y"])
     mouse.warp(int(detail["x"]), int(detail["y"]))
 elif action == "move":
     print "move", int(detail["x"]), int(detail["y"])
     mouse.move(int(detail["x"]), int(detail["y"]))
 elif action == "mouseDownLeft":
     print "mouseDownLeft"
     mouse.mouseDown()
 elif action == "mouseUpLeft":
     print "mouseUpLeft"
     mouse.mouseUp()
 elif action == "mouseDownRight":
     print "mouseDownRight"
     mouse.mouseDown(3)
 elif action == "mouseUpRight":
     print "mouseUpRight"
     mouse.mouseUp(3)
 else:
     print "unknown request", data
     socket.send("{state:false}")
Example #30
0
def mouse_scroll():
    x, y = mouse.get_position()
    mouse.move(500, 250, absolute=True, duration=0)
    mouse.wheel(2)
    mouse.move(x, y, absolute=True, duration=0)
Example #31
0
 def maintain_spot_until_full(self, column_nums):
     columns = self.columns
     while columns and not (columns[column_nums[0]]
                            and columns[column_nums[1]]):
         mouse.move(*self.placements[column_nums[0]])
         columns = self.columns
Example #32
0
def mouse_left(lp):
    mouse.move(-sense, 0, False, 0)