예제 #1
0
    def __init__(self, need_pretrained, device):
        # xwininfo -name eggnoggplus
        self.monitor = {"top": 70, "left": 64, "width": 1440, "height":960}
        self.sct = mss()
        self.resize_factor = self.monitor['width']//240 #width 240, height 160
        self.pil2tensor = transforms.ToTensor()
        self.device = device


        self.delay = int(130e3)
        self.xdo = Xdo()
        self.win_id = max(self.xdo.search_windows(winname=b'eggnoggplus'))

        #swap to window
        self.xdo.activate_window(self.win_id)
        self.xdo.send_keysequence_window_down(self.win_id, b'v')
        self.xdo.send_keysequence_window_up(self.win_id, b'v')

        #init observation network
        self.observation = Observation(need_pretrained=need_pretrained).to(device)

        #init noop prev_action
        self.prev_action = [[2,2], #x_action
                            [2,2], #y_action
                            [False, False], #jump_action
                            [False, False]] #stab_action

        #grab first 4 frames
        self.states = self.get_single_state()[0]
        for _ in range(3):
            self.states = torch.cat((self.states, self.get_single_state()[0]), dim=2) # pylint: disable=no-member
def helloworld():
    from xdo import Xdo
    xdo = Xdo()
    win_id = xdo.select_window_with_click()

    from pprint import pprint
    # pprint(win_id)
    pprint(xdo.get_window_name(win_id))

    win_id = xdo.search_windows('.+Chromium')
    pprint(win_id)
예제 #3
0
def main():
  print('Searching for window of CS...')
  hlcsWindowID = getWindowID()
  while hlcsWindowID == None:
    time.sleep(2)
    hlcsWindowID = getWindowID()
  print('Found CS at', hlcsWindowID)
  time.sleep(10) # Give CS time to launch.
  xdo = Xdo()
  display = Display.Display()
  displayName = display.get_display_name()
  screen = display.screen()
  width = screen.width_in_pixels
  height = screen.height_in_pixels
  # x and y -Center variables should be the center point of our crosshairs aim.
  xCenter = int(???)
  yCenter = int(???)
  while True:
    time.sleep(???) # Limit the CPU useage of this script.
    screenShot = ImageGrab.grab(xdisplay=displayName).load()
    centerPixel = ???

    if isPixelTarget(centerPixel):
      # The escaped character "a" will be interpreted as a
      # bell sound by the terminal, this is quite useful for debugging.
      print('\a')
예제 #4
0
    def __init__(self, x1=None, y1=None, x2=None, y2=None):
        self.x1 = 0
        self.y1 = 0
        xdo = Xdo()
        size = xdo.get_window_size(xdo.get_active_window())
        self.x2 = size.width
        self.y2 = size.height

        if x1:
            self.x1 = x1
        if y1:
            self.y1 = y1
        if x2:
            self.x2 = x2
        if y2:
            self.y2 = y2
예제 #5
0
    def cmd_openApp(self, fn, name=None):
        """
        Open desktop file with "dex" command, then try to focus the window
        """
        subprocess.Popen(['dex', fn], close_fds=True)

        if name:
            # Hopefully the app has started by now
            time.sleep(3)

            # Try to bring it to the front
            #
            # Note: we can't use the pid from the Popen since
            # that's the pid of dex, not the program we started
            xdo = Xdo()
            for windowId in xdo.search_windows(winname=name.encode("utf-8")):
                xdo.activate_window(windowId)
예제 #6
0
 def get_name(self, win_id):
     ''' Retorna el nombre de la ventana que recibe como id '''
     from xdo import Xdo
     from re import sub
     from json import loads
     name = Xdo().get_window_name(win_id)
     name = sub(r"^b'|'*$", '', str(name))
     substituciones = {r'\\xc3\\xb1': 'ñ', r'\\xc3\\xad': 'í'}
     for pat, repl in substituciones.items():
         name = sub(pat, repl, name)
     return name
예제 #7
0
def main():
    print(time.time())
    print('Searching for window of CS...')
    hlcsWindowID = getWindowID()
    while hlcsWindowID == None:
        time.sleep(2)
        hlcsWindowID = getWindowID()
    print('Found CS at', hlcsWindowID)
    time.sleep(5)
    display = Display.Display()
    displayName = display.get_display_name()
    screen = display.screen()
    width = screen.width_in_pixels
    height = screen.height_in_pixels
    print('size1: {}x{}'.format(width, height))
    xCenter = int(width / 2)
    yCenter = int(height / 2)
    xdo = Xdo()
    while True:
        time.sleep(0.01)
        screenShot = ImageGrab.grab(xdisplay=displayName).load()

        if scanArea(screenShot, xCenter, yCenter, 10, 10):
            xdo.click_window(hlcsWindowID, 1)

        target = findTarget(screenShot, xCenter, yCenter, 350, 200)
        if target != None:
            xdo.move_mouse(xCenter + target[0], yCenter + target[1])
def monAndTest():
    import pyinotify
    from xdo import Xdo
    from pprint import pprint
    from time import sleep

    wm = pyinotify.WatchManager()  # Watch Manager
    mask = pyinotify.IN_CLOSE_WRITE  # watched events
    xdo = Xdo()

    def perform_test():
        with cd('/'.join([CWD, '_docker'])), settings(warn_only=True):
            run('docker-compose exec web sh -c "/app/blog/vendor/bin/phpunit /app/blog/tests/"'
                )

    CWD = os.path.dirname(os.path.abspath(__file__))

    class EventHandler(pyinotify.ProcessEvent):
        def process_IN_CLOSE_WRITE(self, event):
            target = os.path.join(event.path, event.name)
            for incl_fileext in incl_fileext_list:
                if target.find(incl_fileext) > 0:
                    perform_test()
                    break
                else:
                    print(
                        yellow('ignore file change for {}'.format(event.path)))

    # excl_lst = ['']
    # excl = pyinotify.ExcludeFilter(excl_lst)

    incl_fileext_list = ['php', 'htm']

    print(green('start monitoring...'))
    handler = EventHandler()
    notifier = pyinotify.Notifier(wm, handler, read_freq=3)
    wdd = wm.add_watch(CWD, mask, rec=True, auto_add=True)

    notifier.loop()
예제 #9
0
def get_areas(area_map):
    """Возвращает координаты квадрата для заданой сетки"""
    if len(area_map) == 0:
        return 0, 0, 0, 0

    xdo = Xdo()
    size = xdo.get_window_size(xdo.get_active_window())
    locations = xdo.get_window_location(xdo.get_active_window())
    wnd_w = int(size.width / len(area_map[0]))
    wnd_h = int(size.height / len(area_map))
    result = []

    for row_n in range(len(area_map)):
        for cell_n in range(len(area_map[row_n])):
            if area_map[row_n][cell_n] == 1:
                result.append(
                    (wnd_w * cell_n + locations.x,
                     wnd_h * row_n + locations.y,
                     wnd_w * cell_n + wnd_w + locations.x,
                     wnd_h * row_n + wnd_h + locations.y)
                )
    return result
예제 #10
0
def monAndReload():
    import pyinotify
    from xdo import Xdo
    from pprint import pprint
    from time import sleep

    wm = pyinotify.WatchManager()  # Watch Manager
    mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE  # watched events

    xdo = Xdo()
    # win_id = xdo.search_windows('.+Chromium.+')

    win_id_vscode = xdo.get_active_window()
    print(red('click chrome window to get win_id_chrome'))
    win_id_chrome = xdo.select_window_with_click()

    CWD = os.path.dirname(os.path.abspath(__file__))

    # CWD = '/home/logic/_workspace/laravel_tryout/app/blog'

    def get_utf8_string(string):
        # return string.encode('utf-8')
        return string

    def reload_browser(win_id_chrome):
        xdo.activate_window(win_id_chrome)
        sleep(0.2)
        for i in range(0, 3):
            xdo.send_keysequence_window(win_id_chrome,
                                        get_utf8_string('Escape'))
        for i in range(0, 3):
            sleep(0.01)
            xdo.send_keysequence_window(win_id_chrome,
                                        get_utf8_string('Control_L+r'))
        # xdo.send_keysequence_window_up(win_id_chrome, get_utf8_string('Control_L+r'))

    def back_to_original(win_id_to_back):
        xdo.activate_window(win_id_to_back)

    def clear_holding_key(win_id_browser, win_id_editor):
        for i in range(0, 5):
            xdo.send_keysequence_window(win_id_browser,
                                        get_utf8_string('Escape'))
            xdo.send_keysequence_window_up(win_id_browser,
                                           get_utf8_string('Control_L'))
            xdo.send_keysequence_window_up(win_id_editor, get_utf8_string('r'))

    def perform_reload(win_id_browser, win_id_editor):
        from datetime import datetime

        print(green('reloading %s' % datetime.now().strftime('%s')))
        reload_browser(win_id_browser)
        back_to_original(win_id_editor)
        clear_holding_key(win_id_browser, win_id_editor)
        print(green('reload done'))
        # pass

    class Reload(Exception):
        pass

    class EventHandler(pyinotify.ProcessEvent):
        def process_IN_CREATE(self, event):
            # target = os.path.join(event.path, event.name)
            # if os.path.isdir(target):
            #     raise Reload()
            pass

        def process_IN_DELETE(self, event):
            # raise Reload()
            pass

        def process_IN_CLOSE_WRITE(self, event):
            target = os.path.join(event.path, event.name)
            for incl_fileext in incl_fileext_list:
                if target.find(incl_fileext) > 0:
                    perform_reload(win_id_chrome, win_id_vscode)
                    break
                else:
                    print(
                        yellow('ignore file change for {}'.format(event.path)))

    # excl_lst = ['']
    # excl = pyinotify.ExcludeFilter(excl_lst)

    incl_fileext_list = ['php', 'htm']

    print(green('start monitoring...'))
    handler = EventHandler()
    notifier = pyinotify.Notifier(wm, handler, read_freq=1)
    wdd = wm.add_watch(CWD, mask, rec=True, auto_add=True)

    notifier.loop()
예제 #11
0
#!/usr/bin/env python2

import subprocess
from xdo import Xdo

xdo = Xdo()
window = xdo.get_active_window()
window_pid = xdo.get_pid_window(window)
window_name = xdo.get_window_name(window)
active_process_pid = subprocess.check_output(
    ['pgrep', '-P', "%s" % window_pid]).split('\n')[0]


def get_pname(id):
    p = subprocess.Popen(
        ["ps -el |grep {} |grep -v zsh |grep ' [R|S] '".format(id)],
        stdout=subprocess.PIPE,
        shell=True)
    return str(p.communicate()[0])


active_process_name = get_pname(active_process_pid)
print(active_process_name)

subprocess.call(
    ['dunstify',
     "Active window %i %s" % (window, active_process_name)])

if 'vim' in active_process_name:
    subprocess.call(['dunstify', 'VIM'])
elif 'Emacs' in active_process_name:
예제 #12
0
d = display.Display(display_num)
root_window = d.screen().root
primary_output_id = randr.get_output_primary(root_window).output
for output_id in randr.get_screen_resources(root_window).outputs:
    o = randr.get_output_info(root_window, output_id, 0)
    if o.crtc != 0:
        c = randr.get_crtc_info(root_window, o.crtc, 0)
        monitors_list[o.name] = { 'width': c.width, 'height': c.height, 'x': c.x, 'y': c.y, 'primary': False }
        if output_id == primary_output_id:
            monitors_list[o.name]['primary'] = True
            primary_monitor = o.name
    else:
        monitors_list_inactive.append(o.name)

# list windows
xdo = Xdo()
windows_list = xdo.search_windows(winname = b'.*')
windows_list.sort()

# getting informations about monitor / window to capture
monitor = None
window = None
if args.source:
    try:
        source_int = int(args.source)
    except:
        source_int = None
    if args.source == 'list-mon':
        print(list_monitors(monitors_list))
        sys.exit(0)
    elif args.source == 'list-win':
예제 #13
0
class GameComponent(ApplicationSession):
    players = {}
    current_button = None
    last_button = None
    press_counter = 0
    save_counter = 0
    xdo = Xdo()
    window = xdo.search_windows(winclass="mGBA".encode('ASCII'))[0]

    def onConnect(self):
        """
        Called by WAMP upon successfully connecting to the crossbar server
        :return: None
        """
        self.join(WAMP_REALM, ["wampcra"], WAMP_USER)

    def onChallenge(self, challenge):
        """
        Called by WAMP for authentication.
        :param challenge: The server's authentication challenge
        :return:          The client's authentication response
        """
        if challenge.method == "wampcra":
            signature = auth.compute_wcs(
                WAMP_PASSWORD.encode('utf8'),
                challenge.extra['challenge'].encode('utf8'))
            return signature.decode('ascii')
        else:
            raise Exception("don't know how to handle authmethod {}".format(
                challenge.method))

    async def game_register(self):
        """
        Register the game with the server. Should be called after initial connection and any time
        the server requests it.
        :return: None
        """

        res = await self.call('game.register',
                              GAME_ID,
                              sequence=GAME_JOIN_SEQUENCE,
                              location=GAME_JOIN_LOCATION)

        err = res.kwresults.get("error", None)
        if err:
            print("Could not register:", err)
        else:
            # This call returns any players that may have already joined the game to ease restarts
            players = res.kwresults.get("players", [])
            await asyncio.gather(*(self.on_player_join(player)
                                   for player in players))

    async def on_button_release(self, button, timestamp=0, badge_id=None):
        """
        Called when a button is released.
        :param button:   The name of the button that was released
        :param badge_id: The ID of the badge that released the button
        :return: None
        """
        player = self.players.get(badge_id, None)

        if not player:
            print("Unknown player:", badge_id)
            return
        # Remove the player from the game if they hold down the start button for a bit
        if button == Button.START:
            if player.start_held(timestamp):
                await self.kick(badge_id)
        player.current_button = None
        self.last_button = None
        await self.calculate_buttons()

    async def set_lights(self, player):
        # Set the lights for the badge to simple colors
        # Note that the order of the lights will be [BOTTOM_LEFT, BOTTOM_RIGHT, TOP_RIGHT, TOP_LEFT]
        self.publish('badge.' + str(player.badge_id) + '.lights_static',
                     *player.light_settings)

    async def on_button_press(self, button, timestamp=0, badge_id=None):
        """
        Called when a button is pressed.
        :param button:   The name of the button that was pressed
        :param badge_id: The ID of the badge that pressed the button
        :return: None
        """

        player = self.players.get(badge_id, None)

        if not player:
            print("Unknown player:", badge_id)
            return

        player.current_button = button
        if button == Button.START:
            player.on_start_press(timestamp)
        self.last_button = button
        await self.calculate_buttons()

    async def calculate_buttons(self):
        totals = {
            x: 0
            for x in
            ["up", "down", "left", "right", "select", "start", "a", "b"]
        }
        for i in self.players.keys():
            if self.players[i].current_button:
                totals[self.players[i].current_button] += 1
        max = 0
        max_item = None
        for i in totals.keys():
            if totals[i] > max:
                max_item = i
                max = totals[i]
        if self.last_button:
            if totals[self.last_button] == max:
                max_item = self.last_button
        if max_item != self.current_button:
            self.current_button = max_item
            await self.push_button()
        for i in self.players.keys():
            if self.players[i].current_button == self.current_button:
                self.players[i].light_settings = [
                    Color.GREEN, Color.GREEN, Color.GREEN, Color.GREEN
                ]
            else:
                self.players[i].light_settings = [
                    Color.RED, Color.RED, Color.RED, Color.RED
                ]
            await self.set_lights(self.players[i])

    async def push_button(self):
        self.press_counter += 1
        if self.press_counter > 100:
            self.press_counter = 0
            self.window = self.xdo.search_windows(
                winclass="mGBA".encode('ASCII'))[0]
            self.xdo.send_keysequence_window(self.window,
                                             'Shift+F1'.encode('ASCII'),
                                             delay=0)
            print("Saved state")
            self.save_counter += 1
            if self.save_counter > 100:
                self.xdo.send_keysequence_window(self.window,
                                                 'Shift+F2'.encode('ASCII'),
                                                 delay=0)
                self.save_counter = 0

        print("Pushing {}".format(self.current_button))
        for i in keycodes.keys():
            if i == self.current_button:
                self.xdo.send_keysequence_window_down(
                    self.window, keycodes[i].encode('ASCII'), delay=0)
            else:
                self.xdo.send_keysequence_window_up(
                    self.window, keycodes[i].encode('ASCII'), delay=0)

    async def kick(self, badge_id):
        """
        Removes a player from the game and informs the server that they have left.
        :param badge_id:
        :return:
        """

        self.publish('game.kick', game_id=GAME_ID, badge_id=badge_id)

    async def on_player_join(self, badge_id):
        """
        Called when a player joins the game, such as by entering a join sequence or entering a
        designated location.
        :param badge_id: The badge ID of the player who left
        :return: None
        """

        print("Badge #{} joined".format(badge_id))

        # Listen for button presses and releases
        press_sub = await self.subscribe(
            self.on_button_press, 'badge.' + str(badge_id) + '.button.press')
        release_sub = await self.subscribe(
            self.on_button_release,
            'badge.' + str(badge_id) + '.button.release')

        # Add an entry to keep track of the player's game-state
        self.players[badge_id] = PlayerInfo(
            badge_id, subscriptions=[press_sub, release_sub])

        await self.set_lights(self.players[badge_id])

    async def on_player_leave(self, badge_id):
        """
        Called when a player leaves the game, such as by leaving a designated location.
        :param badge_id: The badge ID of the player who left
        :return: None
        """

        # Make sure we unsubscribe from all this badge's topics
        print("Badge #{} left".format(badge_id))
        await asyncio.gather(*(s.unsubscribe()
                               for s in self.players[badge_id].subscriptions))
        self.players[badge_id].light_settings = [
            Color.OFF, Color.OFF, Color.OFF, Color.OFF
        ]
        await self.set_lights(self.players[badge_id])
        del self.players[badge_id]

    async def onJoin(self, details):
        """
        WAMP calls this after successfully joining the realm.
        :param details: Provides information about
        :return: None
        """

        # Subscribe to all necessary things
        print("Now connected to the game server!")
        await self.subscribe(self.on_player_join,
                             'game.' + GAME_ID + '.player.join')
        await self.subscribe(self.on_player_leave,
                             'game.' + GAME_ID + '.player.leave')
        await self.subscribe(self.game_register, 'game.request_register')
        await self.game_register()

    def onDisconnect(self):
        """
        Called when the WAMP connection is disconnected
        :return: None
        """
        asyncio.get_event_loop().stop()
예제 #14
0
import os, sys
import pyinotify
from xdo import Xdo
from pprint import pprint
from time import sleep

from datetime import datetime

wm = pyinotify.WatchManager()  # Watch Manager
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE  # watched events

PROJ_HOME = '/home/logic/_workspace/laravel_tryout/app/blog/'
incl_fileext_list = ['php', 'htm']
incl_dir_list = [PROJ_HOME + 'routes', PROJ_HOME + 'resources/views']

xdo = Xdo()
# win_id = xdo.search_windows('.+Chromium.+')

win_id_vscode = xdo.get_active_window()
print('click chrome window to get win_id_chrome')
win_id_chrome = xdo.select_window_with_click()

CWD = os.path.dirname(os.path.abspath(__file__))
# CWD = '/home/logic/_workspace/laravel_tryout/app/blog'


def get_target_log_line(string_input):
    return string_input.replace(PROJ_HOME, '$HOME/')


def get_utf8_string(string):
예제 #15
0
파일: tpyer.py 프로젝트: nvlled/tpyer
from threading import Thread
from concurrent.futures import ThreadPoolExecutor
import pyttsx3


class MainWindow(QMainWindow):
    loadFileSignal = pyqtSignal(object)


app = QApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
win = MainWindow()
ui = Ui_MainWindow()
ui.setupUi(win)
xd = Xdo()
keyboard = Controller()
fileObserver = Observer()

voices = [
    "m1",
    "f1",
    "m4",
    "m7",
    "f5",
    "croak",
    "klatt1",
    "klatt4",
    "whisper",
    "whisperf",
]
예제 #16
0
파일: xutil.py 프로젝트: daswr/daswr
import Xlib
import Xlib.display
from xdo import Xdo

XDO=Xdo()

def _findWindows(display,root,windows=None,winParent=None):
    if winParent: root=winParent
    if not windows:
        windows=[]
    children = root.query_tree().children    
    for win in children:
        windows.append(win)
        if winParent and winParent==root:continue
        _findWindows(display,win,windows)
    return windows


def _parseWindow(display,win):
    winName = win.get_full_property(display.intern_atom('_NET_WM_NAME'),  Xlib.X.AnyPropertyType)
    if not winName: winName=win.get_full_property(display.intern_atom('WM_NAME'),  Xlib.X.AnyPropertyType)

    winPids=win.get_full_property(display.intern_atom('_NET_WM_PID'),  Xlib.X.AnyPropertyType)
    if not winPids: winPids=win.get_full_property(display.intern_atom('WM_PID'),  Xlib.X.AnyPropertyType)
    if not winPids: winPids=win.get_full_property(display.intern_atom('STEAM_GAME'),  Xlib.X.AnyPropertyType)

    if not winName or not winPids: return None
    winName=str(winName.value.decode("utf-8"))
    winPids=winPids.value

    return {"name":winName,"pids":winPids}
예제 #17
0
 def active(self):
     ''' Retorna la id de la ventana activa '''
     from xdo import Xdo
     response = Xdo().get_active_window()
     return response
예제 #18
0
# -*- coding: utf-8 -*-

import pytest

from xdo import (
    MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT, MOUSE_WHEEL_DOWN, MOUSE_WHEEL_UP,
    Xdo)

BROKEN_TEST = pytest.mark.xfail(reason='Something is broken', run=False)

XDO_VERSION = Xdo.version_info()


class TestBase(object):

    def test_move_mouse(self, xdo):
        xdo.move_mouse(200, 100)
        assert xdo.get_mouse_location() == (200, 100, 0)

    def test_move_mouse_left_boundary(self, xdo):
        xdo.move_mouse(-10, 100)
        assert xdo.get_mouse_location() == (0, 100, 0)

    def test_move_mouse_top_boundary(self, xdo):
        xdo.move_mouse(100, -10)
        assert xdo.get_mouse_location() == (100, 0, 0)

    def test_move_mouse_right_boundary(self, xdo):
        xdo.move_mouse(9999, 100)
        assert xdo.get_mouse_location() == (1023, 100, 0)
# Must be run from pi, not ssh
# https://github.com/rshk/python-libxdo
from xdo import Xdo
xdo = Xdo()
xdo.move_mouse(200, 100)
예제 #20
0
# -*- coding: utf-8 -*-

import pytest

from xdo import (MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT, MOUSE_WHEEL_DOWN,
                 MOUSE_WHEEL_UP, Xdo)

BROKEN_TEST = pytest.mark.xfail(reason='Something is broken', run=False)

XDO_VERSION = Xdo.version_info()


class TestBase(object):
    def test_move_mouse(self, xdo):
        xdo.move_mouse(200, 100)
        assert xdo.get_mouse_location() == (200, 100, 0)

    def test_move_mouse_left_boundary(self, xdo):
        xdo.move_mouse(-10, 100)
        assert xdo.get_mouse_location() == (0, 100, 0)

    def test_move_mouse_top_boundary(self, xdo):
        xdo.move_mouse(100, -10)
        assert xdo.get_mouse_location() == (100, 0, 0)

    def test_move_mouse_right_boundary(self, xdo):
        xdo.move_mouse(9999, 100)
        assert xdo.get_mouse_location() == (1023, 100, 0)

    def test_move_mouse_bottom_boundary(self, xdo):
        xdo.move_mouse(100, 9999)
예제 #21
0
파일: main.py 프로젝트: queer/amynia-bot
import cv2

import time

# We time when each last keypress was, and then we make sure to wait at least 32ms
# (2 frames @ 60FPS) so that we don't get multiple keypresses
currentTimeMillis = lambda: int(round(time.time() * 1000))
sTime = currentTimeMillis()
dTime = currentTimeMillis()
fTime = currentTimeMillis()
spaceTime = currentTimeMillis()
jTime = currentTimeMillis()
kTime = currentTimeMillis()
lTime = currentTimeMillis()
WAIT_TIME_MILLIS = 80
xdo = Xdo()
window_id = xdo.search_windows(winname=bytes('osu!cuttingedge', 'utf-8'))[0]

mode = ''

cap = cv2.VideoCapture()
print('Waiting on video...')
cap.open('udp://127.0.0.1:1234/')
if not cap.open:
    print("Not open")
while True:
    # widthxheight+x+y
    # 322x1078+793+0
    err,img = cap.read()
    #if err:
        #print(err)
예제 #22
0
class EggnoggGym():
    """
    Class for the environement
    
    Args:
        None
        
    Attributes:
        monitor (dict): the coodinates of the screen :top, left, width, height
        sct (func): <function mss.factory.mss(**kwargs)>
    """    
    def __init__(self, need_pretrained, device):
        # xwininfo -name eggnoggplus
        self.monitor = {"top": 70, "left": 64, "width": 1440, "height":960}
        self.sct = mss()
        self.resize_factor = self.monitor['width']//240 #width 240, height 160
        self.pil2tensor = transforms.ToTensor()
        self.device = device


        self.delay = int(130e3)
        self.xdo = Xdo()
        self.win_id = max(self.xdo.search_windows(winname=b'eggnoggplus'))

        #swap to window
        self.xdo.activate_window(self.win_id)
        self.xdo.send_keysequence_window_down(self.win_id, b'v')
        self.xdo.send_keysequence_window_up(self.win_id, b'v')

        #init observation network
        self.observation = Observation(need_pretrained=need_pretrained).to(device)

        #init noop prev_action
        self.prev_action = [[2,2], #x_action
                            [2,2], #y_action
                            [False, False], #jump_action
                            [False, False]] #stab_action

        #grab first 4 frames
        self.states = self.get_single_state()[0]
        for _ in range(3):
            self.states = torch.cat((self.states, self.get_single_state()[0]), dim=2) # pylint: disable=no-member



    def act(self, action_tensors):
        #Transforms action_tensor to string for xdo
        #coord: 0 -> left, right, noop (right,left,noop for player2)
        #       1 -> up, down, noop
        #       2 -> jump press
        #       3 -> stab press
        x_action = Categorical(action_tensors[0]).sample()
        y_action = Categorical(action_tensors[1]).sample()
        
        jump_action = action_tensors[2] < torch.rand((2,1), device=self.device)# pylint: disable=no-member
        stab_action = action_tensors[3] < torch.rand((2,1), device=self.device)# pylint: disable=no-member

        string_press = []
        string_lift = []

        #x action
        if x_action[0] == 0:
            string_press.append('q')
        elif x_action[0] == 1:
            string_press.append('d')
        elif x_action[0] == 2 or x_action[0] != self.prev_action[0][0]:
            string_lift.extend(['q','d'])

        if x_action[1] == 0:
            string_press.append('right') #reversed
        elif x_action[1] == 1:
            string_press.append('left') #reversed
        elif x_action[1] == 2 or x_action[1] != self.prev_action[0][1]:
            string_lift.extend(['left','right'])

        #y action
        if y_action[0] == 0:
            string_press.append('z')
        elif y_action[0] == 1:
            string_press.append('s')
        elif y_action[0] == 2 or y_action[0] != self.prev_action[1][0]:
            string_lift.extend(['z','s'])

        if y_action[1] == 0:
            string_press.append('up')
        elif y_action[1] == 1:
            string_press.append('down')
        elif y_action[1] == 2 or y_action[1] != self.prev_action[1][1]:
            string_lift.extend(['up','down'])
        
        #jump action
        if jump_action[0]:
            string_press.append('v')
        else:
            string_lift.append('v')

        if jump_action[1]:
            string_press.append('n')
        else:
            string_lift.append('n')
        
        #stab action
        if stab_action[0]:
            string_press.append('b')
        else:
            string_lift.append('b')
        
        if stab_action[1]:
            string_press.append(',')
        else:
            string_lift.append(',')
        
        #update previous actions
        self.prev_action = [x_action, y_action, jump_action, stab_action]

        #send inputs to eggnogg
        for lift in string_lift:
            pyautogui.keyUp(lift, _pause=False)
        for press in string_press:
            pyautogui.keyDown(press, _pause=False)



    def get_single_state(self):
        with self.sct:
            sct_img = self.sct.grab(self.monitor)
    
            # Create the Image
            state = Image.frombytes("RGB",
                                  sct_img.size,
                                  sct_img.bgra,
                                  "raw",
                                  "BGRX")
            state = state.resize((state.size[0]//self.resize_factor,
                              state.size[1]//self.resize_factor))
            state = self.pil2tensor(state)

            r1 = r2 = 0
            is_terminal = False
            #p1 wins, red water, bottom right
            if state[0, state.shape[1]-1, state.shape[2]-1] == 1.0:
                is_terminal = True
                r1 = 1.0
                r2 = -1.0
            #p2 wins, green water, bottom left
            elif state[1, state.shape[1]-1, 0] == 1.0:
                is_terminal = True
                r1 = -1.0
                r2 = 1.0
            
            state = state.unsqueeze(0)
            #b,3,320,480
            state = state.unsqueeze(2)
            #b,3,1,320,480

            #flip image and swap red and green channels
            state_inversed = state.flip([-1])[:,[1,0,2],:,:,:]

            #cat state and inversed on batch dimension
            state = torch.cat((state, state_inversed), dim=0)# pylint: disable=no-member
        return state.to(self.device).detach_(), (r1, r2), is_terminal


    def reset(self):
        pyautogui.write('zqsdvbn,')
        pyautogui.keyUp('up')
        pyautogui.keyUp('left')
        pyautogui.keyUp('down')
        pyautogui.keyUp('right')

        pyautogui.keyDown('f5')
        pyautogui.keyUp('f5')

    def step(self, action_tensor):
        #remove oldest state
        self.states = self.states.split([1,3], dim=2)[1]
        #2,3,3,320,480

        #act
        self.act(action_tensor)

        #get state
        state, reward, is_terminal = self.get_single_state()

        self.states = torch.cat((self.states, state), dim=2)# pylint: disable=no-member
        #2,3,4,320,480
        with torch.autograd.no_grad():
            obs = self.observation(self.states)

        return obs, reward, is_terminal
예제 #23
0
def xdo(xvfb):
    from xdo import Xdo
    return Xdo(xvfb.display)
            print("Release.")
            clicked = False
            rightClicked = False
            xdo.mouse_up(0, MOUSE_LEFT)

    fd.close()


if __name__ == "__main__":
    os.system("modprobe uinput")
    print("Wait for X to be fully loaded")
    time.sleep(30)
    os.environ['DISPLAY'] = ":0"
    os.environ['XAUTHORITY'] = "/home/pi/.Xauthority"
    print("Enable Touch")
    xdo = Xdo()

    tasks = []
    loop = asyncio.get_event_loop()

    context = pyudev.Context()
    print("Checking devices already plugged-in...")
    for device in context.list_devices(subsystem='hidraw'):
        check_device(device)

    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by(subsystem='hidraw')
    print("Waiting for touch device connection...")

    for device in iter(monitor.poll, None):
        print("HID device notification.  ACTION: ", device.get('ACTION'))
예제 #25
0
from xdo import Xdo
import matplotlib.pyplot as plt
import pyautogui

delay = int(130e3)
xdo = Xdo()
win_id = max(xdo.search_windows(winname=b'eggnoggplus'))

xdo.activate_window(win_id)

xdo.send_keysequence_window_down(win_id, b'v', 0)
xdo.send_keysequence_window_up(win_id, b'v', 0)
"""
plt.pause(2)
xdo.send_keysequence_window_down(win_id, b'a+d+Left+Right+w+s+Up+Down+v+n+comma',0)
print(1)
xdo.send_keysequence_window_up(win_id, b'a+d+Left+Right+w+s+Up+Down+v+n+comma',delay)
print(2)
#xdo.send_keysequence_window_up(win_id, b'a+d+Left+Right+w+s+Up+Down+v+n+comma',0)
#plt.pause(2)
"""
pyautogui.keyDown(',')
예제 #26
0
async def term(editor, args):
    command = args.command
    if command:
        command += "\n"
    window_name = r"^Tilix:".encode("utf-8")
    xdo = Xdo()
    editor_window = xdo.get_active_window()
    windows = xdo.search_windows(window_name, only_visible=True)
    if not windows:
        return error("Tilix window not found")
    term = windows[0]
    xdo.focus_window(term)
    if command:
        xdo.enter_text_window(term, command.encode("utf-8"))
        xdo.focus_window(editor_window)
    else:
        xdo.raise_window(term)
    return result()
예제 #27
0
version = "1.0.2"

import time
import re
import argparse
from os import path
from sys import argv, exit
from watchgod import watch
from xdo import Xdo
xdo = Xdo()

progname = path.basename(argv[0])
desc = "{} - Send keypress events when selected files are modified".format(progname)
argparser = argparse.ArgumentParser(description=desc)
argparser.add_argument("filenames",   type=str,   nargs="*", help="filenames to include")
argparser.add_argument("--filenames", type=str,   nargs="+", help="filenames to include")
argparser.add_argument("--filepat",   default="", type=str,  help="filename regex to include")
argparser.add_argument("--xfilepat",  default="", type=str,  help="filename regex to exclude")
argparser.add_argument("--delay",     default=0,  type=float,  help="number of seconds to delay refresh")
argparser.add_argument("--winpat",    default="", type=str,
        help="a window name regex, reload only when selected window has the matching regex")
argparser.add_argument("--version",   action="store_true", help="show version")
args = argparser.parse_args()

filepat   = args.filepat or None
xfilepat  = args.xfilepat or None
winpat    = args.winpat or None
filenames = [path.abspath(f) for f in args.filenames]
key = "F5"

def included(filename):
예제 #28
0
# Import libraries for NN
import numpy as np
import tensorflow as tf
import keras
from keras.models import model_from_json
from keras import layers
from keras.callbacks import Callback
from keras.models import Model
from keras.models import Sequential
from keras.utils import to_categorical
from sklearn.metrics import confusion_matrix, f1_score, precision_score, recall_score
from itertools import groupby

# Library initialization
xdo = Xdo()
pygame.init()
sct = mss()

# Screen Settings:
display_width = 640
display_height = 400

# General variables:
idle_counter = 0
res_x = 124
res_y = 50
cords = {
    'top': 70,
    'left': 5,
    'width': display_width,
예제 #29
0
 def __init__(self, outport=None, multiplier=None):
     from xdo import Xdo, CURRENTWINDOW
     self.xdo = Xdo()
     self.CURRENTWINDOW = CURRENTWINDOW
     self.multiplier = multiplier
예제 #30
0
def start_ns(url):

    # First, create the copy of the hard drive
    if DEBUG:
        print "creating the HD"

    # kill any previous binaries
    for proc in psutil.process_iter():
        if proc.name() == "previous":
            proc.kill()

    tar = tarfile.open(PRISTINE_HARD_DISK, 'r:gz')
    tar.extractall(ACTUAL_HARD_DISK_DIR)

    if DEBUG:
        print "done creating the HD"

    with pyvirtualdisplay.smartdisplay.SmartDisplay(visible=0,
                                                    size=(1300,
                                                          900)) as v_display:
        if DEBUG:
            print v_display
            print v_display.display

        with easyprocess.EasyProcess(PREVIOUS_BINARY) as previous:

            time.sleep(.50)
            xdo = Xdo()

            done = False
            while not done:
                wins = xdo.search_windows('Previous')
                # check if alive
                if not previous.is_alive():
                    print "Error, couldn't boot emulator"
                    return
                if wins:
                    done = True
                    window = wins[0]
                else:
                    time.sleep(.50)

            # Get the relative X and Y for the window
            loc = xdo.get_window_location(window)

            print "Booting up"

            # wait until we get to the login screen
            wait_until_login_screen(xdo, loc, window, v_display)

            print "Finally booted"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            log_into_ns(xdo, window)

            print "Waiting to log in"

            # wait for the screen to load
            wait_until_login_desktop(xdo, loc, window, v_display)

            print "Logged in"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Send the data
            send_url_to_ns(url)

            send_copy_command(xdo, window)

            time.sleep(.50)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            print "Starting the old dog"

            send_start_www_command(xdo, window)

            # Wait until WWW is ready
            wait_until_www_ready(xdo, loc, window, v_display)

            print "That old dog is ready"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Close out the terminal
            # Command-q is the keyboard shortcut to quit
            xdo.send_keysequence_window(window, "Super_L+q")
            time.sleep(.50)
            select_open_document(xdo, loc, window)

            # Wait until Document Inspector is open
            print "Sending your input"
            wait_until_document_inspector_open(xdo, loc, window, v_display)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            move_to_address_field(xdo, loc, v_display)
            time.sleep(.50)
            xdo.click_window(window, 1)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Paste that shit!
            # Command-v is the keyboard shortcut
            xdo.send_keysequence_window(window, "Super_L+v")
            time.sleep(.50)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            print "That old dog can still visit URLs!"

            # if DEBUG:
            #     input("Wait for debugging")

            # Open it!
            xdo.send_keysequence_window(window, "Return")

            print "tbl would be proud"

            # Wait for 5 seconds, taking screenshots
            for i in xrange(5):
                time.sleep(1)
                current_image = v_display.waitgrab()
                send_screen_shot(current_image)

        # Crazy hack b/c something is sending an error message:
        # "XIO:  fatal IO error 0 (Success) on X server ":1001""
        # Which is freaking crazy, doesn't make any
        devnull = open(os.devnull, 'w')
        os.dup2(devnull.fileno(), 2)
예제 #31
0
#!/usr/bin/env python3

import os, sys
from pprint import pprint

from xdo import Xdo

xdo = Xdo()

# win_id = xdo.select_window_with_click()
# print(win_id)
print(xdo.search_windows(winclass='Chrome'.encode(), only_visible=True))

# xdo.enter_text_window(win_id, 'Python rocks!')
예제 #32
0
from xdo import Xdo
from time import sleep
from loremipsum import get_sentences
from random import randint
xdo = Xdo()
sleep(5)
win_id = xdo.get_focused_window()
while True:
    texts = get_sentences(randint(1,5))
    speed = randint(50000, 1000000)
    for text in texts:
        xdo.enter_text_window(win_id, text, speed)
    xdo.send_keysequence_window(win_id, "Return")