我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pygame.K_t()。
def keyboard_loop(self): while not rospy.is_shutdown(): acc = 0 yaw = 0 keys = pygame.key.get_pressed() for event in pygame.event.get(): if event.type==pygame.QUIT:sys.exit() if(keys[pygame.K_s]): self.send_highway_start(1) if(keys[pygame.K_t]): self.send_highway_start(2) if(keys[pygame.K_UP]): acc = self.acc elif(keys[pygame.K_DOWN]): acc = -self.acc if(keys[pygame.K_LEFT]): yaw = self.yaw elif(keys[pygame.K_RIGHT]): yaw = -self.yaw if(keys[pygame.K_r]): state = 1 self.send_record_state(state) elif(keys[pygame.K_q]): state = 2 self.send_record_state(state) elif(keys[pygame.K_p]): state = 0 self.send_record_state(state) self.send_control(acc, yaw) self.rate.sleep()
def init(): add_key(pygame.K_w) add_key(pygame.K_s) add_key(pygame.K_a) add_key(pygame.K_d) add_key(pygame.K_c) add_key(pygame.K_r) add_key(pygame.K_q) add_key(pygame.K_e) add_key(pygame.K_g) add_key(pygame.K_t) # Adds a new key to be tracked for input
def run(self): """ Run emulator """ self.reboot_pc() is_input_capitalized = False # http://stackoverflow.com/a/28931488 pygame.event.clear() while self.running: for event in pygame.event.get(): if event.type == pygame.QUIT: self.running = False elif event.type == pygame.KEYDOWN: kc, kn = pygame_to_cc(pygame.key.name(event.key)) if kn == "caps lock": is_input_capitalized = not is_input_capitalized kn = "" elif kn == "left shift" or kn == "right shift": kn = "" is_input_capitalized = True if event.key == pygame.K_t and pygame.key.get_mods() & pygame.KMOD_CTRL: self.computer.queue_event("terminate") continue if kc != 0: self.computer.queue_event("key", kc) if kn != "": self.computer.queue_event("char", kn.upper() if is_input_capitalized else kn.lower()) elif event.type == pygame.KEYUP: kc, kn = pygame_to_cc(pygame.key.name(event.key)) if kn == "left shift" or kn == "right shift": is_input_capitalized = False if kc != 0: self.computer.queue_event("key_up", kc) elif event.type == pygame.MOUSEBUTTONDOWN: self.computer.queue_event( "mouse_click", event.button, int((event.pos[0] / self.display.get_width()) * self.cc_display.width) + 1, int((event.pos[1] / self.display.get_height()) * self.cc_display.height) + 1 ) pygame.event.clear() self.display.fill(DisplayColors.BLACK) self.computer.update() self.cc_display.draw() pygame.display.flip() self.clock.tick()