def on_click(x, y, button, pressed):
  global last_time
  global last_pos
  global mouse_moved
  if button == Button.left:
    if pressed is True:
      mouse_moved = 0
      last_pos = [x, y]
      last_time = time.time()
    if pressed is False:
      is_within_threshold = False
      is_within_timeout = True
      if threshold > abs(last_pos[0] - x) \
      and threshold > abs(last_pos[1] - y):
        is_within_threshold = True
      if (time.time() - last_time) * 1000 > timeout:
        is_within_timeout = False
      if is_within_timeout is False \
      and is_within_threshold is True \
      and mouse_moved == 0:
        key = KeyController()
        #key.press(Key.menu)
        #key.release(Key.menu)
        mouse = Controller()
        mouse.press(Button.right)
        mouse.release(Button.right)
      last_pos = [-1, -1]
      last_time = -1
예제 #2
0
 def __init__(self, do_reset=False):
     if do_reset:
         self.set_mouse_positions()
     else:
         self.position_dict = self.get_mouse_positions()
     self.mouse = MouseController()
     self.keyboard = KeyController()
     self.threads = []
 def __init__(self, keys, modifier=None):
     self._pressing = False
     self._key_controller = KeyController()
     self._last_pressed = 0
     self._keys = keys
     self._modifier = modifier
     self._index = 0
     self._key_length = len(keys)
     self._modifier = self._get_modifier(modifier)
예제 #4
0
def playRec():
    statusTv['text']= "Playing"
    statusTv['fg']= 'green'
    root.update()
    data = pickle.load( open( "data.p", "rb" ) )
    mouse = Controller()
    keyc= KeyController()
    play(data, mouse, keyc) 
    statusTv['text']= "Played Successfully"
예제 #5
0
def playRec():
    statusTv['text']= "Playing"
    statusTv['fg']= 'green'
    root.update()
    name= nameE.get();
    data = pickle.load( open( "recordings/{}_0_input.p".format(name), "rb" ) )
    mouse = Controller()
    keyc= KeyController()
    play(data, mouse, keyc) 
    statusTv['text']= "Played Successfully"
예제 #6
0
def playRec():
    statusTv['text'] = "Playing"
    statusTv['fg'] = 'green'
    root.update()

    name = nameE.get()
    fname = "data/{}_0_input.p".format(name)

    data = pickle.load(open(fname, "rb"))
    mouse = Controller()
    keyc = KeyController()
    play(data, mouse, keyc)
예제 #7
0
def playInLoop(): 
    global live, key_listener
    live= True
    key_listener = keyboard.Listener(on_release=on_release)
    key_listener.start()
    statusTv['text']= "Press HOME to Stop"
    statusTv['fg']= 'red'
    data = pickle.load( open( "data.p", "rb" ) )
    mouse = Controller()
    keyc= KeyController()
    while(live):
        play(data, mouse, keyc)
    statusTv['text']= "Stopped Successfully"
    statusTv['fg']= "green"
예제 #8
0
 def __init__(self):
     self.mouse = Controller()
     self.keyboard = KeyController()
     self.chat_colors = [
         (1, 10, 19),  # chatbox body color
         (14, 23, 30),
     ]
     self.lockin_colors = [
         (92, 91, 87),  # button border
     ]
     self.player_joined_colors = [
         (66, 66, 65),
         (66, 66, 66),
     ]
예제 #9
0
def playInLoop(): 
    global live, key_listener
    live= True
    key_listener = keyboard.Listener(on_release=on_release)
    key_listener.start()
    statusTv['text']= "Press HOME to Stop"
    statusTv['fg']= 'red'
    name= nameE.get();
    data = pickle.load( open( "recordings/{}_0_input.p".format(name), "rb" ) )
    mouse = Controller()
    keyc= KeyController()
    while(live):
        play(data, mouse, keyc)
    statusTv['text']= "Stopped Successfully"
    statusTv['fg']= "green"
예제 #10
0
def gaming(ip):
    port = 5000
    game_machine = socket.socket()
    game_machine.connect((ip, port))
    data = game_machine.recv(4096)
    print("Message received: ", data.decode())

    mouse = MouseController()
    mouse_listener = MouseListener(on_click=on_click)
    mouse_listener.start()

    keyboard = KeyController()
    keyboard_listener = KeyListener(on_press=on_press, on_release=on_release)
    keyboard_listener.start()

    width, height = send_resolution(game_machine)

    # Streaming video
    while True:
        # Retrieves frame
        frame = stream(game_machine)

        # Displays frame
        cv2.namedWindow("Streaming", cv2.WND_PROP_FULLSCREEN)
        cv2.setWindowProperty("Streaming", cv2.WND_PROP_FULLSCREEN,
                              cv2.WINDOW_FULLSCREEN)
        cv2.imshow("Streaming", frame)
        if cv2.waitKey(1) == 27:
            break
        game_machine.send("Received".encode())
        print("Received")

        # Send mouse position
        send_mouse_pos(game_machine, mouse, width, height)

        # Send mouse clicks
        send_mouse_clicks(game_machine, CLICKS)
        CLICKS.clear()

        # Send keyboard input
        send_keyboard_input(game_machine, KEYPRESS)
        KEYPRESS.clear()
        CURRENT_KEY.clear()

    keyboard_listener.stop()
    mouse_listener.stop()
    cv2.destroyAllWindows()
    game_machine.close()
예제 #11
0
def playScript(waitingTime, type, action, details):
    eventCount = 0
    mouse = MouseController()
    keyboard = KeyController()
    for t in waitingTime:
        time.sleep(int(t) / 1000)
        if type[eventCount] == 'Mouse':
            if action[eventCount] == 'Scrolled':
                # Move mouse to the right position
                arguments = details[eventCount].split(" ", 1)
                coordinates = arguments[0].split(",", 1)
                xpos = coordinates[0][1:]
                ypos = coordinates[1][:-1]
                mouse.position = (coordinates[0][1:], coordinates[1][:-1])

                # Get the right scroll arguments and perform scroll
                scrollArgs = arguments[1].split(",", 1)
                stArg = scrollArgs[0][1:]
                ndArg = scrollArgs[1][:-1]
                mouse.scroll(int(stArg), int(ndArg))
            else:
                # Move mouse to the right position
                coordinates = details[eventCount].split(",", 1)
                xpos = coordinates[0][1:]
                ypos = coordinates[1][:-1]
                mouse.position = (xpos, ypos)
                # Press and release
                mouse.press(stringToButton(str(action)))
                mouse.release(stringToButton(str(action)))
        else:
            # Remove quotation marks
            event = action[eventCount].replace("'", "")
            if details[eventCount] == 'Press':
                if len(event) == 1:
                    keyboard.press(event)
                else:
                    keyboard.press(stringToKey(event))
            else:
                if len(event) == 1:
                    keyboard.release(event)
                else:
                    keyboard.release(stringToKey(event))

        eventCount += 1
예제 #12
0
파일: server.py 프로젝트: Stantl3r/Gamebox
def streaming():
    port = 5000
    stream_machine = socket.socket()
    host_name = socket.gethostbyname(socket.gethostname())
    stream_machine.bind((host_name, port))
    stream_machine.listen()
    print(host_name)

    while True:
        # Initializations
        conn, addr = stream_machine.accept()
        conn.send("Testing connection . . .".encode())
        image = ImageGrab.grab()

        mouse = MouseController()
        keyboard = KeyController()

        width, height = calc_resolution(conn)
        # Streaming video
        while True:
            convert(image, conn)

            #Wait for receive message, then captures screen again
            conn.recv(1096).decode()
            image = ImageGrab.grab()
            print("New Image")

            # Move mouse
            move_mouse(conn, mouse, width, height)

            # Click mouse
            click_mouse(conn, mouse)

            # Keyboard
            press_keys(conn, keyboard)

        conn.close()
예제 #13
0
from time import sleep
from time import time
import pickle

# Setup arduino
arduino = Serial(ARDUINO_PORT, BAUD_RATE, timeout=0.1)

# Application configuration
windowSize = [400, 450]
windowLocation = [750, 200]
windowTitle = "IR +"
window = Tk()

# Pynput configuration
mouse = MouseController()
keyboard = KeyController()

commandOptions = actions
isReceiverRunning = False
performActionFlag = None
toggleBtnText = None
commandBoxText = None
messageLabelText = None
decodedSignal = ''
configMap = {}
lastAction = ''
lastActionTime = 0
thresholdTime = 700
typingThresholdTime = 100
clickThresholdTime = 100
typingIndex = 0
예제 #14
0
class Player:

    mouse = Controller()
    keyboard = KeyController()
    cursorController = CursorController()

    oldX = 0
    oldY = 0
    x = 0
    y = 0

    def __init__(self):
        self.screen = Screen()
        # self.getPosition()

    def getPosition(self):
        self.oldX = self.x
        self.oldY = self.y

        coordinates = self.screen.getScreenCoordinates()
        print(coordinates, 'getPosition')
        self.x = coordinates[0]
        self.y = coordinates[1]

    def getRotation(self):
        return self.screen.getScreenRotation()

    def getRotationToTarget(self, desX, desY):
        AN = self.getRotation()
        AD = self.getAngle(desX, desY)

        print(AN, AD)

        if AN + AD > 360:
            angle = math.ceil((AN + AD) - 360)
        else:
            angle = math.ceil(AN + AD)

        return [angle, (360 - AD) * -1] if AD > 180 else [angle, AD]

    def moveTo(self, desX, desY):

        while True:
            if (self.inLandingArea(desX, desY, 1.5, 1.5)):
                self.keyboard.release('w')
                return

            angle = self.getRotationToTarget(desX, desY)
            self.rotateDegrees(angle, desX, desY)
            self.keyboard.press('w')
            print(angle)

            for i in range(24):
                time.sleep(0.125)
                self.getPosition()

                print(self.inLandingArea(desX, desY, 1.0, 1.0), 'test')
                if (self.inLandingArea(desX, desY, 1.0, 1.0)):
                    self.keyboard.release('w')
                    return
            self.keyboard.release('w')

    def rotateDegrees(self, angle, desX, desY, turnSpeed=0.005):
        direction = 1

        if angle[1] < 0:
            direction = -1

        self.mouse.press(Button.right)

        for i in range(abs(math.floor((1600 / 360) * angle[1]))):
            time.sleep(turnSpeed)
            self.mouse.move(direction * 1, 0)

        time.sleep(1)
        self.mouse.release(Button.right)

    def getAngle(self, desX, desY):
        self.getPosition()
        self.keyboard.press('s')
        time.sleep(1)
        self.keyboard.release('s')
        self.getPosition()

        a = np.array([self.oldX, self.oldY])
        b = np.array([self.x, self.y])
        c = np.array([desX, desY])

        ang = math.degrees(
            math.atan2(c[1] - b[1], c[0] - b[0]) -
            math.atan2(a[1] - b[1], a[0] - b[0]))
        return ang + 360 if ang < 0 else ang

    def inLandingArea(self, desX, desY, marginX, marginY):
        if desX != '' and desY != '' and self.x != '' and self.y != '':
            return abs(desX - self.x) <= marginX and abs(desY -
                                                         self.y) <= marginY

        return False

    def changeImg(self, pathToImage):

        black = (0, 0, 0)
        white = (255, 255, 255)
        threshold = (190, 190, 190)

        # Open input image in grayscale mode and get its pixels.
        img = Image.open(pathToImage).convert("LA")
        pixels = img.getdata()

        newPixels = []

        # Compare each pixel
        for pixel in pixels:
            if pixel < threshold:
                newPixels.append(black)
            else:
                newPixels.append(white)

        # Create and save new image.
        newImg = Image.new("RGB", img.size)
        newImg.putdata(newPixels)
        newImg.save(pathToImage)
        return newImg

    def ascend(self, seconds):
        pyautogui.press('c')
        time.sleep(2)

        self.keyboard.press(Key.space)
        time.sleep(seconds)
        self.keyboard.release(Key.space)

    def descend(self):
        self.mouse.click(Button.right)

        while True:
            time.sleep(0.7)

            if (self.getSpeed() == 0):
                pyautogui.press('c')
                time.sleep(1.5)
                return

    def moveToOre(self):
        time.sleep(0.5)
        self.cursorController.toOre(8)
        time.sleep(0.5)
        self.mouse.click(Button.right)
        while True:
            time.sleep(1)

            if (self.getSpeed() == 0):
                return

    def mineOre(self):
        time.sleep(0.5)
        self.cursorController.toOre(8)
        time.sleep(0.5)
        self.mouse.click(Button.right)
        time.sleep(3.5)

    def getSpeed(self):
        return self.screen.getPlayerSpeed()

    def getOre(self, desX, desY):
        self.cursorController.zoomIn()
        self.moveTo(desX, desY)
        time.sleep(0.1)
        self.cursorController.lookDown()
        time.sleep(0.1)
        result = self.cursorController.toOre()

        if result:
            time.sleep(0.1)
            self.cursorController.moveNextToOre()
            time.sleep(0.1)
            self.descend()
            self.cursorController.zoomOut()
            time.sleep(0.1)
            self.moveToOre()
            time.sleep(0.1)
            self.moveToOre()
            time.sleep(0.5)
            self.ascend(5)

        self.cursorController.lookStraight()
        # if not(result):
        #     self.cursorController.zoomOut()

        return True
예제 #15
0
 def __init__(self):
     self.keyboard = KeyController()
     self.mouse = MouseController()
예제 #16
0
 def setup_pynput(self):
     """ Create mouse and keyboard controllers, setup hotkeys """
     self.keyboard = KeyController()
     self.mouse = MouseController()