How to use the pyboy.windowevent function in pyboy

To help you get started, we’ve selected a few pyboy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Baekalfen / PyBoy / pyboy / window / debug_window.py View on Github external
def get_events(self):
        events = []
        for event in sdl2.ext.get_events():
            if event.type == sdl2.SDL_QUIT:
                events.append(windowevent.QUIT)
            elif event.type == sdl2.SDL_KEYDOWN:
                events.append(KEY_DOWN.get(event.key.keysym.sym, windowevent.PASS))
            elif event.type == sdl2.SDL_KEYUP:
                events.append(KEY_UP.get(event.key.keysym.sym, windowevent.PASS))
            elif event.type == sdl2.SDL_WINDOWEVENT:
                if event.window.windowID == 1:
                    if event.window.event == sdl2.SDL_WINDOWEVENT_FOCUS_LOST:
                        events.append(windowevent.PAUSE)
                    elif event.window.event == sdl2.SDL_WINDOWEVENT_FOCUS_GAINED:
                        events.append(windowevent.UNPAUSE)
                elif event.window.event == sdl2.SDL_WINDOWEVENT_LEAVE:
                    self.window_focus(event.window.windowID, False)
            else:
                click = event.type == sdl2.SDL_MOUSEBUTTONUP and event.button.button == sdl2.SDL_BUTTON_LEFT
                if ((0 <= event.motion.x < 2**16) and
                    (0 <= event.motion.y < 2**16) and
github Baekalfen / PyBoy / pyboy / window / window_opengl.py View on Github external
self.events.append(windowevent.RELEASE_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.RELEASE_BUTTON_START)
        else:
            if c == 'a':
                self.events.append(windowevent.PRESS_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.PRESS_BUTTON_B)
            elif c == chr(27):
                self.events.append(windowevent.QUIT)
            elif c == 'd':
                self.events.append(windowevent.DEBUG_TOGGLE)
            elif c == ' ':
                self.events.append(windowevent.PRESS_SPEED_UP)
            elif c == 'i':
                self.events.append(windowevent.SCREEN_RECORDING_TOGGLE)
            elif c == chr(8):
                self.events.append(windowevent.PRESS_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.PRESS_BUTTON_START)
github Baekalfen / PyBoy / pyboy / window / window_opengl.py View on Github external
self.events.append(windowevent.RELEASE_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.RELEASE_BUTTON_B)
            elif c == 'z':
                self.events.append(windowevent.SAVE_STATE)
            elif c == 'x':
                self.events.append(windowevent.LOAD_STATE)
            elif c == ' ':
                self.events.append(windowevent.RELEASE_SPEED_UP)
            elif c == chr(8):
                self.events.append(windowevent.RELEASE_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.RELEASE_BUTTON_START)
        else:
            if c == 'a':
                self.events.append(windowevent.PRESS_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.PRESS_BUTTON_B)
            elif c == chr(27):
                self.events.append(windowevent.QUIT)
            elif c == 'd':
                self.events.append(windowevent.DEBUG_TOGGLE)
            elif c == ' ':
                self.events.append(windowevent.PRESS_SPEED_UP)
            elif c == 'i':
                self.events.append(windowevent.SCREEN_RECORDING_TOGGLE)
            elif c == chr(8):
                self.events.append(windowevent.PRESS_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.PRESS_BUTTON_START)
github Baekalfen / PyBoy / examples / tetris_bot.py View on Github external
else:
            window = 'SDL2'
        pyboy = PyBoy(filename, window_type=window, window_scale=3, bootrom_file=bootROM)
        pyboy.set_emulation_speed(0)
        print("Screen pos:", pyboy.get_screen_position())

        first_brick = False
        tile_map = pyboy.get_window_tile_map()
        for frame in range(5282): # Enough frames to get a "Game Over". Otherwise do: `while not pyboy.tick():`
            pyboy.tick()
            # print ("frame:", frame)

            # Start game. Just press Start and A when the game allows us.
            # The frames are not 100% accurate.
            if frame == 144:
                pyboy.send_input(windowevent.PRESS_BUTTON_START)
            elif frame == 145:
                pyboy.send_input(windowevent.RELEASE_BUTTON_START)
            elif frame == 152:
                pyboy.send_input(windowevent.PRESS_BUTTON_A)
            elif frame == 153:
                pyboy.send_input(windowevent.RELEASE_BUTTON_A)
            elif frame == 156:
                pyboy.send_input(windowevent.PRESS_BUTTON_A)
            elif frame == 157:
                pyboy.send_input(windowevent.RELEASE_BUTTON_A)
            elif frame == 162:
                pyboy.send_input(windowevent.PRESS_BUTTON_A)
            elif frame == 163:
                pyboy.send_input(windowevent.RELEASE_BUTTON_A)

            elif frame == 4480:
github Baekalfen / PyBoy / pyboy / window / window_opengl.py View on Github external
def _glkeyboard(self, c, x, y, up):
        if up:
            if c == 'a':
                self.events.append(windowevent.RELEASE_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.RELEASE_BUTTON_B)
            elif c == 'z':
                self.events.append(windowevent.SAVE_STATE)
            elif c == 'x':
                self.events.append(windowevent.LOAD_STATE)
            elif c == ' ':
                self.events.append(windowevent.RELEASE_SPEED_UP)
            elif c == chr(8):
                self.events.append(windowevent.RELEASE_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.RELEASE_BUTTON_START)
        else:
            if c == 'a':
                self.events.append(windowevent.PRESS_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.PRESS_BUTTON_B)
            elif c == chr(27):
                self.events.append(windowevent.QUIT)
            elif c == 'd':
                self.events.append(windowevent.DEBUG_TOGGLE)
            elif c == ' ':
github Baekalfen / PyBoy / pyboy / window / window_opengl.py View on Github external
def _glkeyboard(self, c, x, y, up):
        if up:
            if c == 'a':
                self.events.append(windowevent.RELEASE_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.RELEASE_BUTTON_B)
            elif c == 'z':
                self.events.append(windowevent.SAVE_STATE)
            elif c == 'x':
                self.events.append(windowevent.LOAD_STATE)
            elif c == ' ':
                self.events.append(windowevent.RELEASE_SPEED_UP)
            elif c == chr(8):
                self.events.append(windowevent.RELEASE_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.RELEASE_BUTTON_START)
        else:
            if c == 'a':
                self.events.append(windowevent.PRESS_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.PRESS_BUTTON_B)
            elif c == chr(27):
github Baekalfen / PyBoy / pyboy / window / window_opengl.py View on Github external
def _glkeyboard(self, c, x, y, up):
        if up:
            if c == 'a':
                self.events.append(windowevent.RELEASE_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.RELEASE_BUTTON_B)
            elif c == 'z':
                self.events.append(windowevent.SAVE_STATE)
            elif c == 'x':
                self.events.append(windowevent.LOAD_STATE)
            elif c == ' ':
                self.events.append(windowevent.RELEASE_SPEED_UP)
            elif c == chr(8):
                self.events.append(windowevent.RELEASE_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.RELEASE_BUTTON_START)
        else:
            if c == 'a':
                self.events.append(windowevent.PRESS_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.PRESS_BUTTON_B)
            elif c == chr(27):
                self.events.append(windowevent.QUIT)
            elif c == 'd':
                self.events.append(windowevent.DEBUG_TOGGLE)
            elif c == ' ':
                self.events.append(windowevent.PRESS_SPEED_UP)
            elif c == 'i':
                self.events.append(windowevent.SCREEN_RECORDING_TOGGLE)
            elif c == chr(8):
                self.events.append(windowevent.PRESS_BUTTON_SELECT)
            elif c == chr(13):
github Baekalfen / PyBoy / pyboy / window / debug_window.py View on Github external
def get_events(self):
        events = []
        for event in sdl2.ext.get_events():
            if event.type == sdl2.SDL_QUIT:
                events.append(windowevent.QUIT)
            elif event.type == sdl2.SDL_KEYDOWN:
                events.append(KEY_DOWN.get(event.key.keysym.sym, windowevent.PASS))
            elif event.type == sdl2.SDL_KEYUP:
                events.append(KEY_UP.get(event.key.keysym.sym, windowevent.PASS))
            elif event.type == sdl2.SDL_WINDOWEVENT:
                if event.window.windowID == 1:
                    if event.window.event == sdl2.SDL_WINDOWEVENT_FOCUS_LOST:
                        events.append(windowevent.PAUSE)
                    elif event.window.event == sdl2.SDL_WINDOWEVENT_FOCUS_GAINED:
                        events.append(windowevent.UNPAUSE)
                elif event.window.event == sdl2.SDL_WINDOWEVENT_LEAVE:
                    self.window_focus(event.window.windowID, False)
            else:
                click = event.type == sdl2.SDL_MOUSEBUTTONUP and event.button.button == sdl2.SDL_BUTTON_LEFT
                if ((0 <= event.motion.x < 2**16) and
                    (0 <= event.motion.y < 2**16) and
                        (0 <= event.motion.windowID < 2**16)):
                    self.mouse(click, event.motion.windowID, event.motion.x, event.motion.y)

        return events
github Baekalfen / PyBoy / pyboy / window / window_opengl.py View on Github external
def _glkeyboard(self, c, x, y, up):
        if up:
            if c == 'a':
                self.events.append(windowevent.RELEASE_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.RELEASE_BUTTON_B)
            elif c == 'z':
                self.events.append(windowevent.SAVE_STATE)
            elif c == 'x':
                self.events.append(windowevent.LOAD_STATE)
            elif c == ' ':
                self.events.append(windowevent.RELEASE_SPEED_UP)
            elif c == chr(8):
                self.events.append(windowevent.RELEASE_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.RELEASE_BUTTON_START)
        else:
            if c == 'a':
                self.events.append(windowevent.PRESS_BUTTON_A)
            elif c == 's':
github Baekalfen / PyBoy / pyboy / window / window_opengl.py View on Github external
self.events.append(windowevent.LOAD_STATE)
            elif c == ' ':
                self.events.append(windowevent.RELEASE_SPEED_UP)
            elif c == chr(8):
                self.events.append(windowevent.RELEASE_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.RELEASE_BUTTON_START)
        else:
            if c == 'a':
                self.events.append(windowevent.PRESS_BUTTON_A)
            elif c == 's':
                self.events.append(windowevent.PRESS_BUTTON_B)
            elif c == chr(27):
                self.events.append(windowevent.QUIT)
            elif c == 'd':
                self.events.append(windowevent.DEBUG_TOGGLE)
            elif c == ' ':
                self.events.append(windowevent.PRESS_SPEED_UP)
            elif c == 'i':
                self.events.append(windowevent.SCREEN_RECORDING_TOGGLE)
            elif c == chr(8):
                self.events.append(windowevent.PRESS_BUTTON_SELECT)
            elif c == chr(13):
                self.events.append(windowevent.PRESS_BUTTON_START)