Exemplo n.º 1
0
def openURL():
	"""opens website automatically if the resolution of the screen is usual ( HD or FHD ), else asks the user to open it manually"""
	width, heigth = screen.get_size()

	if heigth == 1080:
		mouse.smooth_move(200, 60)
		mouse.click(mouse.LEFT_BUTTON)
		mouse.click(mouse.LEFT_BUTTON)
		mouse.click(mouse.LEFT_BUTTON)
	elif heigth == 768:
		mouse.smooth_move(200, 60)
		mouse.click(mouse.LEFT_BUTTON)
		mouse.click(mouse.LEFT_BUTTON)
		mouse.click(mouse.LEFT_BUTTON)
	else:
		print 'Please open http://www.nytimes.com/interactive/science/rock-paper-scissors.html then type OK'
		if 'ok'.lower() == raw_input():
			print 'TY'
	time.sleep(1)

	speed = 0
	key.type_string('http',speed)
	key.tap('.', key.MOD_SHIFT)
	key.tap('6', key.MOD_SHIFT)
	key.tap('6', key.MOD_SHIFT)
	key.type_string('www.nytimes.com',speed)
	key.tap('6', key.MOD_SHIFT)
	key.type_string('interactive',speed)
	key.tap('6', key.MOD_SHIFT)
	key.type_string('science',speed)
	key.tap('6', key.MOD_SHIFT)
	key.type_string('rock-paper-scissors.html',speed)
	key.tap('6', key.MOD_SHIFT)
	key.tap(key.K_RETURN)
Exemplo n.º 2
0
def initalize():
	"""checks the arguments, resolution, initalizes the play"""
	signal.signal(signal.SIGINT, handler)

	if len(sys.argv) == 2:
		arg = sys.argv[1]; 
	else:
		arg = ''

	width, heigth = screen.get_size()
	if not (heigth == 1080 or heigth == 768):
		print 'Unsupported resolution!'
		print 'Supported resolutions: 1920 x 1080, 1366 x 768'
		sys.exit(-1)
		

	if arg == '--help' or arg == '-h' or not arg == '':
		print 'Usage:'
		print "-open Google Chrome, make sure it's full sized and nothing covers the address bar"
		print '-execute the program with python interpreter ($python', sys.argv[0],'or ./' +  sys.argv[0] +')'
		print
		print 'supported resolutions: 1920 x 1080, 1366 x 768'
		sys.exit(0)
	else:
		openURL()
		chooseDifficulty('novice')
Exemplo n.º 3
0
def act(guess):
	"""moves the cursor to the appropriate area of the screen"""
	
	width, heigth = screen.get_size()

	if heigth == 1080:
		if guess == 'r':
			mouse.smooth_move(660,580)
			mouse.click(mouse.LEFT_BUTTON)
		elif guess == 'p':
			mouse.smooth_move(740,580)
			mouse.click(mouse.LEFT_BUTTON)
		elif guess == 's':
			mouse.smooth_move(560,580)
			mouse.click(mouse.LEFT_BUTTON)
	elif heigth == 768:	
		if guess == 'r':
			mouse.smooth_move(350,480)
			mouse.click(mouse.LEFT_BUTTON)
		elif guess == 'p':
			mouse.smooth_move(500,480)
			mouse.click(mouse.LEFT_BUTTON)
		elif guess == 's':
			mouse.smooth_move(220,480)
			mouse.click(mouse.LEFT_BUTTON)
Exemplo n.º 4
0
def chooseDifficulty(difficulty):
	"""Moves the cursor to the difficulty button specified by the parameter"""
	
	width, heigth = screen.get_size()

	if heigth == 1080:
		if difficulty == 'novice':
			mouse.smooth_move(1300,710)
			time.sleep(10)
			mouse.click(mouse.LEFT_BUTTON)
		else:
			mouse.smooth_move(1300,810)
			time.sleep(10)
			mouse.click(mouse.LEFT_BUTTON)
	elif heigth == 768:
		if difficulty == 'novice':
			mouse.smooth_move(1000,630)
			time.sleep(10)
			mouse.click(mouse.LEFT_BUTTON)
		else:
			mouse.smooth_move(1000,680)
			time.sleep(10)
			mouse.click(mouse.LEFT_BUTTON)
Exemplo n.º 5
0
from base64 import b64encode, b64decode
from zlib import decompress

from autopy.screen import get_size
from autopy.bitmap import capture_screen
from PIL import Image
from tornado import ioloop, web, websocket

try:
    from cStringIO import StringIO
except:
    from StringIO import StringIO

__all__ = ['Handler']

size = get_size()


def get_data(quality):
    data = capture_screen().to_string().split(',')[-1]
    data = b64decode(data)
    data = decompress(data)
    data = Image.frombytes('RGB', size,
                           data).convert('RGB',
                                         (0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0))

    sio = StringIO()
    data.save(sio, 'jpeg', quality=quality)
    data = sio.getvalue()
    sio.close()
    return data
Exemplo n.º 6
0
 def __init__(self):
     self.config = yaml.load(open('settings.yaml'))
     self.screen_size = screen.get_size()
Exemplo n.º 7
0
from pysoundcard import Stream, continue_flag
from autopy import mouse, screen
import numpy as np
import time

RATE = 44100
CHUNK = 2048

screen_size = screen.get_size()

MOUSE_SPEED = 15  # px
MOUSE_TARGET = [0, 0]

DB_MUL = 5
SCREEN_LEFT_DB = -16
SCREEN_RIGHT_DB = 2

SCREEN_TOP_HZ = 100
SCREEN_BOT_HZ = 1500

def determine_pitch(chunk):
    w = np.fft.fft(chunk)
    freqs = np.fft.fftfreq(len(w))
    idx = np.argmax(np.abs(w))
    freq = freqs[idx]
    return abs(freq * RATE)

def new_mouse_position(current, target, speed):
    if current == target:
        return current
    d = target - current
Exemplo n.º 8
0
def move_middle_bottom():
    """Moves the mouse to the bottom middle of the screen."""
    size = screen.get_size()
    middle_bottom = (size[0]/2, size[1]-1)
    mouse.move(middle_bottom[0],middle_bottom[1])
Exemplo n.º 9
0
from autopy.screen import get_size
from autopy.bitmap import capture_screen
from PIL import Image
from tornado import ioloop, web, websocket

try:
  from cStringIO import StringIO
except:
  from StringIO import StringIO

__all__ = [
    'Handler'
]

size = get_size()

def get_data(quality):
    data = capture_screen().to_string().split(',')[-1]
    data = b64decode(data)
    data = decompress(data)
    data = Image.frombytes('RGB', size, data).convert('RGB', (
      0, 0, 1, 0,
      0, 1, 0, 0,
      1, 0, 0, 0))

    sio = StringIO()
    data.save(sio, 'jpeg', quality=quality)
    data = sio.getvalue()
    sio.close()
    return data
Exemplo n.º 10
0
    def dataReceived(self, data):
        #print "datareceived", data
        while data:
            try:
                decode, index = json_decode(data)
            except ValueError:
                # something went wrong.. FIXME
                return

            data = data[index:]

            if not isinstance(decode, dict):
                # something went wrong, gtfo for now, FIXME
                return

            command = decode.get('command')
            if command == 'mouse':
                pos = mouse.get_pos()
                action = decode.get('action')

                if action == 'click':
                    for i in range(decode.get('n') or 1):
                        mouse.click(BUTTONS[decode.get('b') - 1])

                elif action == 'move':
                    try:
                        mouse.move(pos[0] + decode.get('dx'),
                                   pos[1] + decode.get('dy'))
                    except ValueError:
                        pass

                elif action == 'press':
                    mouse.toggle(True, BUTTONS[decode.get('b') - 1])

                elif action == 'release':
                    mouse.toggle(False, BUTTONS[decode.get('b') - 1])

            elif command == 'type':
                key.type_string(decode['string'])

            elif command == 'press_key':
                key.toggle(getattr(key, 'K_' + decode['key'].upper()), True)

            elif command == 'release_key':
                key.toggle(getattr(key, 'K_' + decode['key'].upper()), False)

            elif command == 'kill':
                self.kill_app(decode['uid'])

            elif command == 'capture':
                pos = mouse.get_pos()
                size = decode.get('size')
                maxx, maxy = screen.get_size()
                rect = ((
                    max(0, min((pos[0] - size[0] / 2), maxx - size[0])),
                    max(0, min((pos[1] - size[1] / 2), maxy - size[1]))
                ), (size[0], size[1]))

                try:
                    bitmap.capture_screen(rect).save('tmp.png')
                except ValueError:
                    return

                self.send(mouse_pos=(pos[0] - rect[0][0], pos[1] - rect[0][1]))

                #print "sending capture"
                self.send_image('tmp.png')

            elif decode.get('run') in zip(*self.commands)[0]:
                self.execute(decode.get('run'), decode.get('arguments'))
Exemplo n.º 11
0
    def _is_mouse_on_the_right(self):
        screen_resolution_x = screen.get_size()[0]
        mouse_pos_x = mouse.get_pos()[0]

        return mouse_pos_x >= screen_resolution_x / 2 /2