Python pygame.K_x() Examples

The following are 4 code examples of pygame.K_x(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygame , or try the search function .
Example #1
Source File: sprites.py    From gamedev with MIT License 6 votes vote down vote up
def get_keys(self):
        # TODO: add WASD?
        keystate = pg.key.get_pressed()
        if keystate[pg.K_LEFT]:
            if not self.beam_firing:
                self.rot_speed = PLAYER_ROT_SPEED
        if keystate[pg.K_RIGHT]:
            if not self.beam_firing:
                self.rot_speed = -PLAYER_ROT_SPEED
        if keystate[pg.K_UP]:
            self.acc = vec(0, -self.thrust_power).rotate(-self.rot)
            self.engine_emitter.count = 50
        if keystate[pg.K_SPACE]:
            self.shoot()
        if keystate[pg.K_z]:
            self.hyper()
        if keystate[pg.K_x]:
            self.shoot_wpn2() 
Example #2
Source File: pygame.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _map_keys(self):
        key_map = self.io.key_map

        key_map[imgui.KEY_TAB] = pygame.K_TAB
        key_map[imgui.KEY_LEFT_ARROW] = pygame.K_LEFT
        key_map[imgui.KEY_RIGHT_ARROW] = pygame.K_RIGHT
        key_map[imgui.KEY_UP_ARROW] = pygame.K_UP
        key_map[imgui.KEY_DOWN_ARROW] = pygame.K_DOWN
        key_map[imgui.KEY_PAGE_UP] = pygame.K_PAGEUP
        key_map[imgui.KEY_PAGE_DOWN] = pygame.K_PAGEDOWN
        key_map[imgui.KEY_HOME] = pygame.K_HOME
        key_map[imgui.KEY_END] = pygame.K_END
        key_map[imgui.KEY_DELETE] = pygame.K_DELETE
        key_map[imgui.KEY_BACKSPACE] = pygame.K_BACKSPACE
        key_map[imgui.KEY_ENTER] = pygame.K_RETURN
        key_map[imgui.KEY_ESCAPE] = pygame.K_ESCAPE
        key_map[imgui.KEY_A] = pygame.K_a
        key_map[imgui.KEY_C] = pygame.K_c
        key_map[imgui.KEY_V] = pygame.K_v
        key_map[imgui.KEY_X] = pygame.K_x
        key_map[imgui.KEY_Y] = pygame.K_y
        key_map[imgui.KEY_Z] = pygame.K_z 
Example #3
Source File: battle.py    From universalSmashSystem with GNU General Public License v3.0 5 votes vote down vote up
def debugLoop(self):
        self.draw()
        pygame.display.update()
        try:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.exit_status = 1
                    self.debug_mode = False
                
                if event.type == pygame.KEYDOWN:
                    if (event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT):
                        self.debug_mode = False
                    elif event.key == pygame.K_TAB:
                        self.debug_console.set_trace() #Drop into the console
                    elif event.key == pygame.K_LEFT:
                        self.cameraX = -5
                    elif event.key == pygame.K_RIGHT:
                        self.cameraX = 5
                    elif event.key == pygame.K_UP:
                        self.cameraY = -5
                    elif event.key == pygame.K_DOWN:
                        self.cameraY = 5
                    elif event.key == pygame.K_z:
                        self.zoomVal = 0.01
                    elif event.key == pygame.K_x:
                        self.zoomVal = -0.01
                elif event.type == pygame.KEYUP:
                    if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                        self.cameraX = 0
                    elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
                        self.cameraY = 0
                    elif event.key == pygame.K_z or event.key == pygame.K_x:
                        self.zoomVal = 0
                for cont in self.controllers:
                    cont.getInputs(event)
                
            
            self.stage.moveCamera(self.cameraX,self.cameraY)
            self.stage.zoomCamera(self.zoomVal)    
        except bdb.BdbQuit:
            pass 
Example #4
Source File: rc_control_test.py    From AutoRCCar with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def steer(self):

        while self.send_inst:
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    key_input = pygame.key.get_pressed()

                    # complex orders
                    if key_input[pygame.K_UP] and key_input[pygame.K_RIGHT]:
                        print("Forward Right")
                        self.ser.write(chr(6).encode())

                    elif key_input[pygame.K_UP] and key_input[pygame.K_LEFT]:
                        print("Forward Left")
                        self.ser.write(chr(7).encode())

                    elif key_input[pygame.K_DOWN] and key_input[pygame.K_RIGHT]:
                        print("Reverse Right")
                        self.ser.write(chr(8).encode())

                    elif key_input[pygame.K_DOWN] and key_input[pygame.K_LEFT]:
                        print("Reverse Left")
                        self.ser.write(chr(9).encode())

                    # simple orders
                    elif key_input[pygame.K_UP]:
                        print("Forward")
                        self.ser.write(chr(1).encode())

                    elif key_input[pygame.K_DOWN]:
                        print("Reverse")
                        self.ser.write(chr(2).encode())

                    elif key_input[pygame.K_RIGHT]:
                        print("Right")
                        self.ser.write(chr(3).encode())

                    elif key_input[pygame.K_LEFT]:
                        print("Left")
                        self.ser.write(chr(4).encode())

                    # exit
                    elif key_input[pygame.K_x] or key_input[pygame.K_q]:
                        print("Exit")
                        self.send_inst = False
                        self.ser.write(chr(0).encode())
                        self.ser.close()
                        break

                elif event.type == pygame.KEYUP:
                    self.ser.write(chr(0).encode())