def lost(self): self.game_over = True self.lives = " NO LIVES" if android: self.text_messages.append( widgets.TextMessage( self.screen_getter(), " Play again? Y/n", Vector(self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2 - 120), duration=9999999, size=32, initialdelay=9999990)) android.show_keyboard() else: self.text_messages.append( widgets.TextMessage(self.screen_getter(), " Play again? Y/n", Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=9999999, size=32, initialdelay=9999990)) self.add_to_highscore()
def mainLoop(self, screen): while True: for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: (mX, mY) = pygame.mouse.get_pos() for s in self.sliders: if s.getXLoc()* const.scaleFactor <= mX < (s.getXLoc() + 24) * const.scaleFactor and (s.getYLoc()+(s.getValue()*10)) * const.scaleFactor <= mY < (s.getYLoc()+(s.getValue()*10) + 24 )* const.scaleFactor: self.slide(s, screen) # done if int(floor(33*const.scaleFactor)) <= mX < int(ceil(82*const.scaleFactor)) and int(floor(237*const.scaleFactor)) <= mY < int(ceil(266*const.scaleFactor)): self.displayField, r = load_image.load_image(os.path.join('MENU', "createBox2.png") ) self.updateDisplay(screen, 'name') if android: android.show_keyboard() self.name = self.getInput(screen, '') return self.getBall() elif event.type == pygame.QUIT: os.sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: self.displayField, r = load_image.load_image(os.path.join('MENU', "createBox2.png")) self.updateDisplay(screen, 'name') if android: android.show_keyboard() self.name = self.getInput(screen, '') return self.getBall() elif event.key == pygame.K_ESCAPE: os.sys.exit() self.updateDisplay(screen, 'stats') while (pygame.event.wait().type != pygame.KEYDOWN): pass
def user_answer(self, block, trial): reverse = block.get_factor('reverse') correct_answer = trial.get_factor('sequence') seq_length = trial.get_factor('sequence_length') input_method = self.exp.config.get('ANDROID', 'input_method') if android and input_method == 'keyboard': android.show_keyboard() self.exp.keyboard.clear() if not android or input_method == 'keyboard' or input_method == 'none': user_input = io.TextInput(_('remember_sequence_reverse') if reverse else _('remember_sequence'), length=seq_length, position=self.input_offset, user_text_size=self.input_text_size ).get().strip() android.hide_keyboard() if android else None else: pass answer = user_input[::-1] if reverse else user_input format = {'sequence': correct_answer, 'sequence_length': seq_length, 'sequence_reverse': correct_answer[::-1]} if answer.strip() == correct_answer: self.exp._show_message('', 'correct_trial', format=format) else: self.exp._show_message('', 'incorrect_trial_reverse' if reverse else 'incorrect_trial', format=format) return(answer == correct_answer, user_input)
def request_keyboard( self, callback, target, input_type='text', keyboard_suggestions=True ): keyboard = super(WindowPygame, self).request_keyboard( callback, target, input_type, keyboard_suggestions) if android and not self.allow_vkeyboard: android.show_keyboard(target, input_type) return keyboard
def toggle_keyboard(): """ Togle soft keyboard visibility. """ global keyboard_visible if keyboard_visible: android.hide_keyboard() else: android.show_keyboard() keyboard_visible = not keyboard_visible
def show_virtual_keyboard(self, visible=True): if android == None: return self.persistent_virtual_keyboard = visible if visible: android.show_keyboard() else: android.hide_keyboard()
def lost(self): self.game_over = True self.lives = "DEAD" if android: self.text_messages.append(widgets.TextMessage(self.screen, "You died. Play again? Y/n", Vector(self.screen.get_width() / 2, self.screen.get_height() / 2 - 120), duration=9999999, size=32, initialdelay=9999990)) android.show_keyboard() else: self.text_messages.append(widgets.TextMessage(self.screen, "You died. Play again? Y/n", Vector(self.screen.get_width() / 2, self.screen.get_height() / 2), duration=9999999, size=32, initialdelay=9999990)) self.add_to_highscore()
def sf(self,v): self._focused = v if android: if isinstance(v,editbox): if not self._keyboard: self._keyboard = True android.show_keyboard() else: if self._keyboard: self._keyboard = False android.hide_keyboard()
def show_virtual_keyboard(self, visible=True): """See openexp._keyboard.legacy""" if android == None: return self.persistent_virtual_keyboard = visible if visible: android.show_keyboard() else: android.hide_keyboard()
def level_complete(self): self.waiting_for_level = True self.collect_all_score() if self.level < self.available_levels: pygame.time.set_timer(self.WAIT_NEW_LEVEL, 1800) self.text_messages.append(widgets.TextMessage(self.screen, "Level Complete!", Vector(self.screen.get_width() / 2, self.screen.get_height() / 2), duration=1800, size=32, initialdelay=800)) else: if android: self.text_messages.append(widgets.TextMessage(self.screen, "Congratulations! You beat all " + str(self.available_levels) + " levels. Play again? Y/n", Vector(self.screen.get_width() / 2, self.screen.get_height() / 2 - 120), duration=9999999, size=24, initialdelay=9999990)) android.show_keyboard() else: self.text_messages.append(widgets.TextMessage(self.screen, "Congratulations! You beat all " + str(self.available_levels) + " levels. Play again? Y/n", Vector(self.screen.get_width() / 2, self.screen.get_height() / 2), duration=9999999, size=24, initialdelay=9999990)) self.add_to_highscore() self.game_over = True
def get_key(self, keylist=None, timeout=None): if not self.persistent_virtual_keyboard and android != None: android.show_keyboard() start_time = pygame.time.get_ticks() time = start_time if keylist == None: keylist = self._keylist if timeout == None: timeout = self.timeout while True: time = pygame.time.get_ticks() for event in pygame.event.get(): if event.type != pygame.KEYDOWN: continue if event.key == pygame.K_ESCAPE: raise osexception("The escape key was pressed.") # TODO The unicode mechanism that ensures compatibility between # keyboard layouts doesn't work for Android, so we use key # names. I'm not sure what effect this will have on non-QWERTY # virtual keyboards. if android != None: key = pygame.key.name(event.key) if len(key) == 1 and (event.mod & pygame.KMOD_LSHIFT or \ event.mod & pygame.KMOD_RSHIFT): key = key.upper() else: # If we're not on Android, simply use the same logic as the # legacy back-end. if event.unicode in invalid_unicode: key = self.key_name(event.key) else: key = event.unicode if keylist == None or key in keylist: if not self.persistent_virtual_keyboard and android != None: android.hide_keyboard() return key, time if timeout != None and time - start_time >= timeout: break # Allow Android interrupt if android != None and android.check_pause(): android.wait_for_resume() if not self.persistent_virtual_keyboard and android != None: android.hide_keyboard() return None, time
def get_key(self, keylist=None, timeout=None): """See openexp._keyboard.legacy""" if not self.persistent_virtual_keyboard and android != None: android.show_keyboard() start_time = pygame.time.get_ticks() time = start_time if keylist == None: keylist = self._keylist if timeout == None: timeout = self.timeout while True: time = pygame.time.get_ticks() for event in pygame.event.get(): if event.type != pygame.KEYDOWN: continue if event.key == pygame.K_ESCAPE: raise osexception("The escape key was pressed.") # TODO The unicode mechanism that ensures compatibility between # keyboard layouts doesn't work for Android, so we use key # names. I'm not sure what effect this will have on non-QWERTY # virtual keyboards. if android != None: key = pygame.key.name(event.key) else: # If we're not on Android, simply use the same logic as the # legacy back-end. if event.unicode in invalid_unicode or \ event.unicode not in printable: key = self.key_name(event.key) else: key = event.unicode if keylist == None or key in keylist: if not self.persistent_virtual_keyboard and android != None: android.hide_keyboard() return key, time if timeout != None and time-start_time >= timeout: break # Allow Android interrupt if android != None and android.check_pause(): android.wait_for_resume() if not self.persistent_virtual_keyboard and android != None: android.hide_keyboard() return None, time
def get_keyboard_top(): from kivy import platform global _keyboard_top_absolute if _keyboard_top_absolute > 0: return _keyboard_top_absolute if platform == 'android': import android #from kivy.clock import Clock from kivy.logger import Logger from time import sleep class Target: password = False keyboard_suggestions = True target = Target() android.show_keyboard(target, 'text') for i in range(50): keyboard_top = android.get_keyboard_height() Logger.info('Theme: android get_keyboard_height return %s' % keyboard_top) try: _keyboard_top_absolute = int(keyboard_top) except Exception: pass if _keyboard_top_absolute > 0: break sleep(0.025) elif platform == 'ios': from kivy.core.window import Window if hasattr(Window, 'keyboard_height') and (Window.keyboard_height > 0): _keyboard_top_absolute = Window.keyboard_height print 'HAS KEYB HEIGHT %s' % _keyboard_top_absolute else: #from kivy.metrics import Metrics _keyboard_top_absolute = int(Window.height * 0.3805) #288.0*Metrics.density print 'DEF KEYB HEIGHT %s' % _keyboard_top_absolute else: _keyboard_top_absolute = _scale_to_theme_dpi(300) return _keyboard_top_absolute
def get_key(self): if not self.persistent_virtual_keyboard and android is not None: android.show_keyboard() start_time = pygame.time.get_ticks() time = start_time keylist = self.keylist timeout = self.timeout while True: time = pygame.time.get_ticks() for event in pygame.event.get(): if event.type != pygame.KEYDOWN: continue if event.key == pygame.K_ESCAPE: self.experiment.pause() # TODO The unicode mechanism that ensures compatibility between # keyboard layouts doesn't work for Android, so we use key # names. I'm not sure what effect this will have on non-QWERTY # virtual keyboards. if android is not None: key = pygame.key.name(event.key) if len(key) == 1 and (event.mod & pygame.KMOD_LSHIFT or \ event.mod & pygame.KMOD_RSHIFT): key = key.upper() else: # If we're not on Android, simply use the same logic as the # legacy back-end. if event.unicode in invalid_unicode: key = self.key_name(event.key) else: key = event.unicode if keylist is None or key in keylist: if not self.persistent_virtual_keyboard and android is not None: android.hide_keyboard() return key, time if timeout is not None and time-start_time >= timeout: break # Allow Android interrupt if android is not None and android.check_pause(): android.wait_for_resume() if not self.persistent_virtual_keyboard and android is not None: android.hide_keyboard() return None, time
def level_complete(self): self.waiting_for_level = True self.collect_all_score() if self.level < self.available_levels: pygame.time.set_timer(self.WAIT_NEW_LEVEL, 1800) self.text_messages.append( widgets.TextMessage(self.screen_getter(), "Level Complete!", Vector( self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=1800, size=32, initialdelay=800)) else: if android: self.text_messages.append( widgets.TextMessage( self.screen_getter(), "Congratulations! You beat all " + str(self.available_levels) + " levels. Play again? Y/n", Vector(self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2 - 120), duration=9999999, size=24, initialdelay=9999990)) android.show_keyboard() else: self.text_messages.append( widgets.TextMessage( self.screen_getter(), "Congratulations! You beat all " + str(self.available_levels) + " levels. Play again? Y/n", Vector(self.screen_getter().get_width() / 2, self.screen_getter().get_height() / 2), duration=9999999, size=24, initialdelay=9999990)) self.add_to_highscore() self.game_over = True
def get_keyboard_top(): from kivy import platform global _keyboard_top_absolute if _keyboard_top_absolute > 0: return _keyboard_top_absolute if platform == 'android': import android #from kivy.clock import Clock from kivy.logger import Logger from time import sleep class Target: password = False keyboard_suggestions = True target = Target() android.show_keyboard(target, 'text') for i in range(50): keyboard_top = android.get_keyboard_height() Logger.info('Theme: android get_keyboard_height return %s' % keyboard_top) try: _keyboard_top_absolute = int(keyboard_top) except Exception: pass if _keyboard_top_absolute > 0: break sleep(0.025) elif platform == 'ios': from kivy.core.window import Window if hasattr(Window, 'keyboard_height') and (Window.keyboard_height > 0): _keyboard_top_absolute = Window.keyboard_height print 'HAS KEYB HEIGHT %s' % _keyboard_top_absolute else: #from kivy.metrics import Metrics _keyboard_top_absolute = int(Window.height*0.3805) #288.0*Metrics.density print 'DEF KEYB HEIGHT %s' % _keyboard_top_absolute else: _keyboard_top_absolute = _scale_to_theme_dpi(300) return _keyboard_top_absolute
def demandeUtilisateur(screen, question, answer=None): "ask(screen, question) -> answer" if android: android.init() android.show_keyboard() entryAnswer = False pygame.font.init() current_string = [] if not answer == None: for i in answer: current_string.append(i) question = question + " : " afficherDialog(screen, question + string.join(current_string, "")) while entryAnswer == False: event = pygame.event.wait() if event.type == pygame.KEYDOWN: inkey = event.key if inkey == pygame.K_BACKSPACE: current_string = current_string[0:-1] elif inkey == pygame.K_RETURN: entryAnswer = True elif inkey == pygame.K_MINUS: current_string.append("_") elif inkey <= 127: current_string.append(chr(inkey)) afficherDialog(screen, question + " " + string.join(current_string, "")) if android: android.hide_keyboard() return string.join(current_string, "")
def mainLoop(self, screen): while True: for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: (mX, mY) = pygame.mouse.get_pos() for s in self.sliders: if s.getXLoc() * const.scaleFactor <= mX < (s.getXLoc( ) + 24) * const.scaleFactor and ( s.getYLoc() + (s.getValue() * 10)) * const.scaleFactor <= mY < ( s.getYLoc() + (s.getValue() * 10) + 24) * const.scaleFactor: self.slide(s, screen) # done if int(floor(33 * const.scaleFactor)) <= mX < int( ceil(82 * const.scaleFactor)) and int( floor(237 * const.scaleFactor)) <= mY < int( ceil(266 * const.scaleFactor)): self.displayField, r = load_image.load_image( os.path.join('MENU', "createBox2.png")) self.updateDisplay(screen, 'name') if android: android.show_keyboard() self.name = self.getInput(screen, '') return self.getBall() elif event.type == pygame.QUIT: os.sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: self.displayField, r = load_image.load_image( os.path.join('MENU', "createBox2.png")) self.updateDisplay(screen, 'name') if android: android.show_keyboard() self.name = self.getInput(screen, '') return self.getBall() elif event.key == pygame.K_ESCAPE: os.sys.exit() self.updateDisplay(screen, 'stats') while (pygame.event.wait().type != pygame.KEYDOWN): pass
def get_key(self, keylist=None, timeout=None): """See openexp._keyboard.legacy""" if android != None: android.show_keyboard() start_time = pygame.time.get_ticks() time = start_time if keylist == None: keylist = self._keylist if timeout == None: timeout = self.timeout while True: time = pygame.time.get_ticks() for event in pygame.event.get(): if event.type != pygame.KEYDOWN: continue if event.key == pygame.K_ESCAPE: raise openexp.exceptions.response_error( \ "The escape key was pressed.") # TODO The unicode mechanism that ensures compatibility between # keyboard layouts doesn't work for Android, so we use key # names. I'm not sure what effect this will have on non-QWERTY # virtual keyboards. key = pygame.key.name(event.key) if keylist == None or key in keylist: if android != None: android.hide_keyboard() return key, time if timeout != None and time-start_time >= timeout: break # Allow Android interrupt if android != None and android.check_pause(): android.wait_for_resume() if android != None: android.hide_keyboard() return None, time
def request_keyboard(self, callback, target, input_type='text'): keyboard = super(WindowPygame, self).request_keyboard( callback, target, input_type) if android and not self.allow_vkeyboard: android.show_keyboard(target, input_type) return keyboard
def question_screen(screen, color, text_color, texto, max_length): # printamos pantalla fondo = Window("", "", WHITE, "DroidSans-Bold.ttf", 1, "sound0.wav", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color, WHITE, WHITE, WHITE) fondo.plot(screen) fuente = load_text_font("DroidSans-Bold.ttf", FNT_DIR, 26) size = fuente.size(texto) mensaje = fuente.render(texto, 1, text_color) screen.blit(mensaje, ((SCREEN_WIDTH / 2) - (size[0] / 2), (SCREEN_HEIGHT / 2) - ((size[1] / 2) * 3) )) # Inicializamos variables y = (SCREEN_HEIGHT / 2) + (size[1]) x = (SCREEN_WIDTH / 2) - (size[1] * (max_length-1) / 2) contador = 0 text = [0, 0, 0, 0] salir = True pygame.gfxdraw.rectangle(screen, (x - 5, y - 5, size[1] * (max_length - 1), 10 + size[1]), WHITE) pygame.display.flip() # Printamos if android: android.show_keyboard() while salir: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_0: if contador < max_length: text[contador] = 0 contador = contador + 1 elif event.key == pygame.K_1: if contador < max_length: text[contador] = 1 contador = contador + 1 elif event.key == pygame.K_2: if contador < max_length: text[contador] = 2 contador = contador + 1 elif event.key == pygame.K_3: if contador < max_length: text[contador] = 3 contador = contador + 1 elif event.key == pygame.K_4: if contador < max_length: text[contador] = 4 contador = contador + 1 elif event.key == pygame.K_5: if contador < max_length: text[contador] = 5 contador = contador + 1 elif event.key == pygame.K_6: if contador < max_length: text[contador] = 6 contador = contador + 1 elif event.key == pygame.K_7: if contador < max_length: text[contador] = 7 contador = contador + 1 elif event.key == pygame.K_8: if contador < max_length: text[contador] = 8 contador = contador + 1 elif event.key == pygame.K_9: if contador < max_length: text[contador] = 9 contador = contador + 1 elif event.key == pygame.K_BACKSPACE: if contador > 0: contador = contador - 1 elif event.key == pygame.K_RETURN: salir = False pygame.gfxdraw.box(screen, (x, y, size[0] * 0.6, size[1]), color) if (contador == 1): mensaje_text = fuente.render("{0}".format(text[0]), 1, WHITE) if (contador == 2): mensaje_text = fuente.render("{0} {1}".format(text[0], text[1]), 1, WHITE) if (contador == 3): mensaje_text = fuente.render("{0} {1} {2}".format(text[0], text[1], text[2]), 1, WHITE) if (contador == 4): mensaje_text = fuente.render("{0} {1} {2} {3}".format(text[0], text[1], text[2], text[3]), 1, WHITE) if (contador > 0): screen.blit(mensaje_text, (x, y)) pygame.display.flip() # Printamos if android: android.hide_keyboard() return text
def request_keyboard(self, *largs): keyboard = super(WindowPygame, self).request_keyboard(*largs) if android and not self.allow_vkeyboard: android.show_keyboard() return keyboard
def keyboardShow(self): # Zobraz klávesnici na Androidu if self.root.onAndroid(): android.show_keyboard()
def get_player(self): name = "" ai = False invert = False shift = False while True: pygame.display.update() for event in pygame.event.get(): if event.type == pygame.KEYUP: shift = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: sys.exit() elif event.key == pygame.K_RETURN: self.add_player_to_list(name,ai,invert) name = "" pygame.display.update(self.name_box) elif event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT: shift = True elif event.key == pygame.K_DELETE or event.key == pygame.K_BACKSPACE: name = name[:-1] self.name.surface = fonts.h1.render(name,1,(0,0,0),(255,255,255)) pygame.draw.rect(self.screen,(255,255,255),self.name_box) self.screen.blit(self.name.surface,self.name.rect) pygame.display.update(self.name_box) elif event.key in [32]+range(48,58)+range(97,123): if len(name)<=16: if shift and event.key in range(97,123): name += chr(event.key).capitalize() else: name += chr(event.key) self.name.surface = fonts.h1.render(name,1,(0,0,0),(255,255,255)) self.screen.blit(self.name.surface,self.name_box,(0,0,self.name_box.width,self.name_box.height)) pygame.display.update(self.name_box) else: print event.key elif event.type == pygame.MOUSEBUTTONUP: if self.add_player.rect.collidepoint(event.pos): self.add_player_to_list(name,ai,invert) name = "" elif self.del_player.rect.collidepoint(event.pos): if len(self.players): self.players.pop() self.draw_player_list() elif self.done.rect.collidepoint(event.pos): if android: android.hide_keyboard() return self.players elif self.ai_off.rect.collidepoint(event.pos): ai = not ai if ai: self.screen.blit(self.ai_on.surface,self.ai_on.rect) else: self.screen.blit(self.ai_off.surface,self.ai_off.rect) pygame.display.update(self.ai_off.rect) elif self.invert_off.rect.collidepoint(event.pos): invert = not invert if invert: self.screen.blit(self.invert_on.surface,self.invert_on.rect) else: self.screen.blit(self.invert_off.surface,self.invert_off.rect) pygame.display.update(self.invert_off.rect) elif self.name_box.collidepoint(event.pos): if android: android.show_keyboard() else: if android: android.hide_keyboard()
def textfield(rect, font, settings, onlynums=False, loadtext=True): """Starts interaction with a text field, handling keyboard input and updating part of the display on that input; returns when Enter is pressed arguments rect - a (x,y,w,h) tuple indicating where the textfield is font - a pygame.font.Font instance fgc - a (r,g,b) tuple indicating the text colour bgc - a (r,g,b) tuple indicating the background colour of the textfield settings - the app settings dict keyword arguments onlynums - Boolean indicating whether only numerical values should be allowed loadtext - Boolean indicating if the current text should be loaded (assuming the function is called via the currently active button!); alternatively all text is deleted when this function is called returns input - string of what was typed in """ # get the display surface disp = pygame.display.get_surface() # clip the display surface, to prevent text from spilling over disp.set_clip(rect) # rect centre textcentre = (rect[0]+rect[2]/2, rect[1]+rect[3]/2) # allowed characters if onlynums: allowed = u'0123456789' else: allowed = keymodsdict.keys() # load the current text if loadtext: text = settings[u'guibuttons'][settings[u'currentscreen']][settings[u'currentbutton']][u'text'] else: text = u"" # if this is Android, show the keyboard if settings[u'android']: android.show_keyboard() # run until Enter is pressed enter = False while not enter: # check if there is any event for event in pygame.event.get(): # check if the event is a keypress if event.type == pygame.KEYDOWN: # convert the keyname into something readable key = pygame.key.name(event.key) # check if the key is Enter if key == u'return': enter = True # remove the last index of the text if the key was backspace elif key == u'backspace' and len(text) > 0: text = text[:-1] # add the input to the text if the key was an allowed key elif key in allowed: # check if the Shift key is pressed (not when using nums) if (event.mod & pygame.KMOD_SHIFT) and not onlynums: # change key value accordingly key = keymodsdict[key] # append key to the text text += key # render the text textsurf = font.render(text, False, settings[u'fgc']) # text position textpos = (int(textcentre[0] - textsurf.get_width()/2), int(textcentre[1]-textsurf.get_height()/2)) # reset text if enter: colour = settings[u'tfbgc'] else: colour = settings[u'tfhbgc'] disp.fill(colour, rect) # blit text to display disp.blit(textsurf, textpos) pygame.display.flip() # allow an Android interrupt if settings[u'android']: if android.check_pause(): android.wait_for_resume() # hide keyboard on Android if settings[u'android']: android.hide_keyboard() # unclip display disp.set_clip(None) return text
def wait(self, keys=None, duration=None, wait_for_keyup=False, check_for_control_keys=True): """Wait for keypress(es) (optionally for a certain amount of time). This function will wait for a keypress and returns the found key as well as the reaction time. (This function clears the event queue!) Parameters ---------- keys : int or list, optional a specific key or list of keys to wait for duration : int, optional maximal time to wait in ms wait_for_keyup : bool, optional if True it waits for key-up check_for_control_keys : bool, optional checks if control key has been pressed (default=True) """ if android is not None: android.show_keyboard() start = Clock._cpu_time() rt = None found_key = None self.clear() if keys is None: keys = self.default_keys if keys is not None and type(keys) is not list: keys = [keys] if wait_for_keyup: target_event = pygame.KEYUP else: target_event = pygame.KEYDOWN pygame.event.pump() done = False while not done: expyriment._active_exp._execute_wait_callback() for event in pygame.event.get(): if check_for_control_keys and Keyboard.process_control_keys(event): done = True elif event.type == target_event: if keys is not None: if event.key in keys: rt = int((Clock._cpu_time() - start) * 1000) found_key = event.key done = True else: rt = int((Clock._cpu_time() - start) * 1000) found_key = event.key done = True if duration and not done: done = int((Clock._cpu_time() - start) * 1000) >= duration time.sleep(0.0005) if self._logging: expyriment._active_exp._event_file_log("Keyboard,received,{0},wait"\ .format(found_key)) if android is not None: android.hide_keyboard() return found_key, rt