Python pygame.K_BACKSPACE Examples

The following are 23 code examples of pygame.K_BACKSPACE(). 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: main-2-class-move.py    From python-examples with MIT License 6 votes vote down vote up
def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_BACKSPACE:
                self.reset()
            if event.key == pygame.K_SPACE:
                self.speed_y = -20
            if event.key == pygame.K_LEFT:                        
                self.speed_x -= 10
            elif event.key == pygame.K_RIGHT:                        
                self.speed_x += 10
            elif event.key == pygame.K_DOWN:                        
                self.gravity += 10
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:                        
                self.speed_x -= -10
            elif event.key == pygame.K_RIGHT:                        
                self.speed_x += -10
            elif event.key == pygame.K_DOWN:                        
                self.gravity += -10 
Example #2
Source File: game031.py    From eduActiv8 with GNU General Public License v3.0 6 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if not self.show_msg:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if char in self.digits:
                        if len(char) > 0 and lhv < self.max_len:
                            self.home_square.value += char
                        else:
                            self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True 
Example #3
Source File: game080.py    From eduActiv8 with GNU General Public License v3.0 6 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if not self.show_msg:
            if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if char in self.digits:
                        if len(char) > 0 and lhv < 2:
                            self.home_square.value += char
                        else:
                            self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True 
Example #4
Source File: game085.py    From eduActiv8 with GNU General Public License v3.0 6 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if not self.show_msg:
            if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER):
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if len(char) > 0 and lhv < 3 and char in self.digits:
                        self.home_square.value += char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
                self.auto_check_reset()
            elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
                self.check_result()
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset() 
Example #5
Source File: game087.py    From eduActiv8 with GNU General Public License v3.0 6 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if not self.show_msg:
            if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER):
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if len(char) > 0 and lhv < self.sollen and char in self.digits:
                        self.home_square.value += char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
                self.auto_check_reset()
            elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
                self.check_result()
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset() 
Example #6
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 #7
Source File: main.py    From python-examples with MIT License 5 votes vote down vote up
def handle_event(self, event):

        if event.type == pygame.MOUSEBUTTONDOWN:
            self.active = self.rect.collidepoint(event.pos)
            self.color = self.color_active if self.active else self.color_inactive
        if event.type == pygame.KEYDOWN:
            if self.active:
                if event.key == pygame.K_RETURN:
                    self.text = ''
                elif event.key == pygame.K_BACKSPACE:
                    self.text = self.text[:-1]
                else:
                    self.text += event.unicode 
Example #8
Source File: pygame_functions.py    From Pygame_Functions with GNU General Public License v2.0 5 votes vote down vote up
def update(self, keyevent):
        key = keyevent.key
        unicode = keyevent.unicode
        if key > 31 and key < 127 and (
                self.maxLength == 0 or len(self.text) < self.maxLength):  # only printable characters
            if keyevent.mod in (1, 2) and self.case == 1 and key >= 97 and key <= 122:
                # force lowercase letters
                self.text += chr(key)
            elif keyevent.mod == 0 and self.case == 2 and key >= 97 and key <= 122:
                self.text += chr(key - 32)
            else:
                # use the unicode char
                self.text += unicode

        elif key == 8:
            # backspace. repeat until clear
            keys = pygame.key.get_pressed()
            nexttime = pygame.time.get_ticks() + 200
            deleting = True
            while deleting:
                keys = pygame.key.get_pressed()
                if keys[pygame.K_BACKSPACE]:
                    thistime = pygame.time.get_ticks()
                    if thistime > nexttime:
                        self.text = self.text[0:len(self.text) - 1]
                        self.image.fill((255, 255, 255))
                        pygame.draw.rect(self.image, (0, 0, 0), [0, 0, self.width - 1, self.boxSize - 1], 2)
                        newSurface = self.font.render(self.text, True, self.fontColour)
                        self.image.blit(newSurface, [10, 5])
                        updateDisplay()
                        nexttime = thistime + 50
                        pygame.event.clear()
                else:
                    deleting = False

        self.image.fill((255, 255, 255))
        pygame.draw.rect(self.image, (0, 0, 0), [0, 0, self.width - 1, self.boxSize - 1], 2)
        newSurface = self.font.render(self.text, True, self.fontColour)
        self.image.blit(newSurface, [10, 5])
        if screenRefresh:
            updateDisplay() 
Example #9
Source File: pygame_functions.py    From Pygame_Functions with GNU General Public License v2.0 5 votes vote down vote up
def update(self, keyevent):
        key = keyevent.key
        unicode = keyevent.unicode
        if key > 31 and key < 127 and (
                self.maxLength == 0 or len(self.text) < self.maxLength):  # only printable characters
            if keyevent.mod in (1, 2) and self.case == 1 and key >= 97 and key <= 122:
                # force lowercase letters
                self.text += chr(key)
            elif keyevent.mod == 0 and self.case == 2 and key >= 97 and key <= 122:
                self.text += chr(key - 32)
            else:
                # use the unicode char
                self.text += unicode

        elif key == 8:
            # backspace. repeat until clear
            keys = pygame.key.get_pressed()
            nexttime = pygame.time.get_ticks() + 200
            deleting = True
            while deleting:
                keys = pygame.key.get_pressed()
                if keys[pygame.K_BACKSPACE]:
                    thistime = pygame.time.get_ticks()
                    if thistime > nexttime:
                        self.text = self.text[0:len(self.text) - 1]
                        self.image.fill((255, 255, 255))
                        pygame.draw.rect(self.image, (0, 0, 0), [0, 0, self.width - 1, self.boxSize - 1], 2)
                        newSurface = self.font.render(self.text, True, self.fontColour)
                        self.image.blit(newSurface, [10, 5])
                        updateDisplay()
                        nexttime = thistime + 50
                        pygame.event.clear()
                else:
                    deleting = False

        self.image.fill((255, 255, 255))
        pygame.draw.rect(self.image, (0, 0, 0), [0, 0, self.width - 1, self.boxSize - 1], 2)
        newSurface = self.font.render(self.text, True, self.fontColour)
        self.image.blit(newSurface, [10, 5])
        if screenRefresh:
            updateDisplay() 
Example #10
Source File: main.py    From Hermit with MIT License 5 votes vote down vote up
def keyupdowncontrol(event):
	global keyseq, showconsole, fullscreen
	if event.type == pygame.QUIT: sys.exit()
	man.keyupdowncontrol(event,horse)

	if event.type == pygame.KEYDOWN:
		if showconsole:
			k = pygame.key.name(event.key)
			#print k
			if k == "return":
				exe("".join(keyseq))
				showconsole = False
			elif k == "space":
				keyseq.append(" ")
			elif k == "-":
				keyseq.append("-")
			elif len(k) == 1:
				keyseq.append(k)
			elif event.key == pygame.K_BACKSPACE :
				if len(keyseq) > 0:
					keyseq.pop()

		if event.key == pygame.K_SLASH:
			showconsole = not showconsole
			if showconsole:
				settings.msg = ["CONSOLE READY.",settings.msgt]
			else:
				settings.msg = ["",settings.msgt]
			keyseq = []

		if event.key == pygame.K_f and not showconsole:
			fullscreen = not fullscreen
			if fullscreen:
				pygame.display.set_mode([width/2,height+50],pygame.FULLSCREEN)
			else:
				pygame.display.set_mode([width/2,height+50])
				pygame.display.set_caption("") 
Example #11
Source File: _utils.py    From pygame-menu with MIT License 5 votes vote down vote up
def test_widget_key_press(widget):
        """
        Test keypress widget.

        :param widget: Widget object
        :type widget: :py:class:`pygame_menu.widgets.core.widget.Widget`
        """
        widget.update(PygameUtils.key(pygame.K_BACKSPACE, keydown=True))
        widget.update(PygameUtils.key(pygame.K_DELETE, keydown=True))
        widget.update(PygameUtils.key(pygame.K_LEFT, keydown=True))
        widget.update(PygameUtils.key(pygame.K_RIGHT, keydown=True))
        widget.update(PygameUtils.key(pygame.K_END, keydown=True))
        widget.update(PygameUtils.key(pygame.K_HOME, keydown=True)) 
Example #12
Source File: game084.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)
        if not self.show_msg:
            if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER):
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][18]:
                    char = event.unicode
                    if len(char) > 0 and lhv < 2 and char in self.digits:
                        self.home_square.value += char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][18]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif event.type == pygame.MOUSEBUTTONUP:
                for each in self.board.units:
                    if each.is_door is True:
                        self.board.all_sprites_list.move_to_front(each)
                if self.board.grid[4][18]:
                    self.check_result()
            elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
                self.check_result()
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset()
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #13
Source File: game034.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)
        if not self.show_msg:
            if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER):
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][16]:
                    char = event.unicode
                    if len(char) > 0 and char in self.digits:
                        self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][16]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif event.type == pygame.MOUSEBUTTONUP:
                for each in self.board.units:
                    if each.is_door is True:
                        self.board.all_sprites_list.move_to_front(each)
                if self.board.grid[4][16]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
                    self.check_result()
            elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
                self.check_result()
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset()
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #14
Source File: game035.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)
        if not self.show_msg:
            if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER):
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                elif not self.board.grid[4][18]:
                    char = event.unicode
                    if len(char) > 0 and char in self.digits:
                        self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEMOTION and self.drag:
                if self.board.grid[4][18]:
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif event.type == pygame.MOUSEBUTTONUP:
                for each in self.board.units:
                    if each.is_door is True:
                        self.board.all_sprites_list.move_to_front(each)
                if self.board.grid[4][18]:
                    self.check_result()
                    self.home_square.value = ""
                    self.home_square.update_me = True
            elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
                self.check_result()
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset()
        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #15
Source File: game071.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if not self.show_msg:
            if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset()
            if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
                self.home_sqare_switch(self.board.active_ship + 1)
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
                self.home_sqare_switch(self.board.active_ship - 1)

            elif event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and not self.correct:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if len(char) > 0 and lhv < 2 and char in self.digits:
                        if lhv == 1:
                            s = self.home_square.value + char
                            if s[0] == "0":
                                self.home_square.value = char
                            else:
                                n = int(s)
                                if n < 20:
                                    self.home_square.value = str(n % 10)
                                    try:
                                        self.carryl[self.home_square.pos_id].value = "1"
                                        self.carryl[self.home_square.pos_id].update_me = True
                                    except:
                                        pass

                                else:
                                    self.home_square.value = char
                        else:
                            self.home_square.value = char
                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEBUTTONUP:
                self.home_sqare_switch(self.board.active_ship) 
Example #16
Source File: game072.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if not self.show_msg:
            if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset()
            if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
                self.home_sqare_switch(self.board.active_ship + 1)
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
                self.home_sqare_switch(self.board.active_ship - 1)
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
                self.home_sqare_switch(self.board.active_ship - self.sumn1n2sl + 1)
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
                self.home_sqare_switch(self.board.active_ship + self.sumn1n2sl)
            elif event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and not self.correct:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if len(char) > 0 and lhv < 2 and char in self.digits:
                        self.home_square.value = char
                        if self.auto_select:
                            self.home_sqare_switch(self.board.active_ship + 1)
                    else:
                        self.home_square.value = ""

                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True

            elif event.type == pygame.MOUSEBUTTONUP:
                self.home_sqare_switch(self.board.active_ship) 
Example #17
Source File: game110.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            active = self.board.active_ship
            if self.missing_number == 1:
                if active == 0:
                    self.change_fract_btn(-1, 0)
                elif active == 1:
                    self.change_fract_btn(1, 0)
            else:
                if active == 0:
                    self.change_fract_btn(0, -1)
                elif active == 1:
                    self.change_fract_btn(0, 1)
            self.auto_check_reset()
        elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
            self.check_result()
        elif event.type == pygame.KEYDOWN:
            lhv = len(self.active_num.value)
            self.changed_since_check = True
            if event.key == pygame.K_BACKSPACE:
                if lhv > 0:
                    self.active_num.value = self.active_num.value[0:lhv - 1]
            else:
                char = event.unicode
                if self.typed and len(char) > 0 and lhv < 3 and char in self.digits:
                    self.active_num.value += char
                elif char in self.digits:
                    self.active_num.value = char
                    self.typed = True
            if len(self.active_num.value) > 0:
                self.result[self.missing_number - 1] = int(self.active_num.value)
            else:
                self.result[self.missing_number - 1] = 0

            self.active_num.update_me = True
            self.mainloop.redraw_needed[0] = True
            self.auto_check_reset() 
Example #18
Source File: game068.py    From eduActiv8 with GNU General Public License v3.0 5 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            active = self.board.active_ship
            if active == 0:
                self.change_fract_btn(-1)
            elif active == 1:
                self.change_fract_btn(1)
            self.auto_check_reset()
        elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
            self.check_result()
        elif event.type == pygame.KEYDOWN:
            self.auto_check_reset()
            lhv = len(self.nm1.value)
            self.changed_since_check = True
            if event.key == pygame.K_BACKSPACE:
                if lhv > 2:
                    self.nm1.value = self.nm1.value[0:lhv - 1]
            else:
                char = event.unicode
                if len(char) > 0 and char in self.digits:
                    self.numbers_disp[0] = int(char)
                    self.nm1.set_value("0.%s" % char)
                    self.check_result()
            self.nm1.update_me = True
            self.mainloop.redraw_needed[0] = True 
Example #19
Source File: draw.py    From rpisurv with GNU General Public License v2.0 5 votes vote down vote up
def check_keypress():
    try:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q or event.key == pygame.K_a or event.key == pygame.K_KP_DIVIDE or event.key == pygame.K_BACKSPACE:
                    logger.debug("Keypress 'a' or 'q' or 'backspace' or 'keypad /' detected.")
                    return "end_event"
                if event.key == pygame.K_n or event.key == pygame.K_SPACE or event.key == pygame.K_KP_PLUS:
                    logger.debug("Keypress 'n' or 'space' or 'keypad +' detected.")
                    return "next_event"
                if event.key == pygame.K_r or event.key == pygame.K_KP_PERIOD or event.key == pygame.K_COMMA:
                    logger.debug("Keypress 'r' or ',' or 'keypad .' detected")
                    return "resume_rotation"
                if event.key == pygame.K_p or event.key == pygame.K_KP_MULTIPLY:
                    logger.debug("Keypress 'p' or 'keypad *' detected")
                    return "pause_rotation"
                for numeric_key_counter, key in enumerate([pygame.K_F1,pygame.K_F2,pygame.K_F3,pygame.K_F4,pygame.K_F5,pygame.K_F6,pygame.K_F7,pygame.K_F8,pygame.K_F9,pygame.K_F10,pygame.K_F11,pygame.K_F12]):
                    if event.key == key:
                        logger.debug("Keypress 'F" + str(numeric_key_counter + 1) + "' detected")
                        return numeric_key_counter
                for numeric_key_counter, key in enumerate([pygame.K_KP0,pygame.K_KP1,pygame.K_KP2,pygame.K_KP3,pygame.K_KP4,pygame.K_KP5,pygame.K_KP6,pygame.K_KP7,pygame.K_KP8,pygame.K_KP9]):
                    if event.key == key:
                        logger.debug("Keypress 'keypad " + str(numeric_key_counter + 1) + "' detected")
                        return numeric_key_counter
                else:
                    return None
    except pygame.error as e:
        logger.debug("Exception " + repr(e))
        exit(0) 
Example #20
Source File: game069.py    From eduActiv8 with GNU General Public License v3.0 4 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if not self.show_msg:
            if event.type == pygame.KEYDOWN:
                self.auto_check_reset()
            if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
                self.home_sqare_switch(self.board.active_ship + 1)
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
                self.home_sqare_switch(self.board.active_ship - 1)
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
                self.home_sqare_switch(self.board.active_ship - self.sumn1n2sl + 1)
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
                self.home_sqare_switch(self.board.active_ship + self.sumn1n2sl)
            elif event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and not self.correct:
                lhv = len(self.home_square.value)
                self.changed_since_check = True
                if event.key == pygame.K_BACKSPACE:
                    if lhv > 0:
                        self.home_square.value = self.home_square.value[0:lhv - 1]
                else:
                    char = event.unicode
                    if (len(char) > 0 and lhv < 2 and char in self.digits):

                        if self.home_square in self.resultl:
                            if lhv == 1:
                                s = self.home_square.value + char
                                if s[0] == "0":
                                    self.home_square.value = char
                                else:
                                    n = int(s)
                                    if n < 20:
                                        self.home_square.value = str(n % 10)
                                        try:
                                            self.carryl[self.home_square.pos_id].value = "1"
                                            self.carryl[self.home_square.pos_id].update_me = True
                                        except:
                                            pass

                                    else:
                                        self.home_square.value = char
                            else:
                                self.home_square.value = char
                        elif self.home_square in self.carryl:
                            if char == "1":
                                self.home_square.value = char
                            else:
                                self.home_square.value = ""

                self.home_square.update_me = True
                self.mainloop.redraw_needed[0] = True
            elif event.type == pygame.MOUSEBUTTONUP:
                self.home_sqare_switch(self.board.active_ship)
            elif event.type == pygame.MOUSEBUTTONDOWN:
                self.auto_check_reset() 
Example #21
Source File: game117.py    From eduActiv8 with GNU General Public License v3.0 4 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin]
            for each in self.text_fields:
                if each.rect.topleft[0] < pos[0] < each.rect.topleft[0] + each.rect.width and \
                        each.rect.topleft[1] < pos[1] < each.rect.topleft[1] + each.rect.height:
                    self.toggle_active_fract(each)
            active = self.board.active_ship
            if active == 0:
                self.change_fract_btn(self.response, -1, 0)
            elif active == 1:
                self.change_fract_btn(self.response, 1, 0)
            elif active == 2:
                self.change_fract_btn(self.response, 0, -1)
            elif active == 3:
                self.change_fract_btn(self.response, 0, 1)
            self.auto_check_reset()
        elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
            self.check_result()
        elif event.type == pygame.KEYDOWN:
            self.auto_check_reset()
            lhv = len(self.current_txt)
            self.changed_since_check = True
            if event.key == pygame.K_BACKSPACE:
                if lhv > 0:
                    self.current_txt = self.current_txt[0:lhv - 1]
                    self.active_fract.value = self.current_txt
                self.active_fract.update_me = True
                if len(self.current_txt) > 0:
                    if self.active_fract == self.sm1a:
                        self.response[0] = int(self.active_fract.value)
                    elif self.active_fract == self.sm1b:
                        self.response[1] = int(self.active_fract.value)


            elif event.key == pygame.K_TAB:
                if self.active_fract == self.sm1a:
                    self.toggle_active_fract(self.sm1b)
                else:
                    self.toggle_active_fract(self.sm1a)
            else:
                char = event.unicode
                if char in self.digits:
                    if len(char) > 0 and lhv < 3 and self.active_fract.value != self.qm:
                        self.current_txt += char
                    else:
                        self.current_txt = char

                    self.active_fract.value = self.current_txt

                    if self.active_fract == self.sm1a:
                        self.response[0] = int(self.active_fract.value)
                        if self.response[0] == self.sum_numbers[0]:
                            self.toggle_active_fract(self.sm1b)
                    elif self.active_fract == self.sm1b:
                        self.response[1] = int(self.active_fract.value)
                    self.active_fract.update_me = True

            self.mainloop.redraw_needed[0] = True 
Example #22
Source File: game030.py    From eduActiv8 with GNU General Public License v3.0 4 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up

        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin]
            self.auto_check_reset()
            for each in self.units:
                if each.rect.topleft[0] < pos[0] < each.rect.topleft[0] + each.rect.width and \
                        each.rect.topleft[1] < pos[1] < each.rect.topleft[1] + each.rect.height:
                    self.toggle_active_unit(each)

        elif event.type == pygame.MOUSEBUTTONUP:
            for each in self.board.units:
                if each.is_door is True:
                    self.board.all_sprites_list.move_to_front(each)
            self.mainloop.redraw_needed[0] = True

        if not self.show_msg:
            if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER):
                if self.active_unit in self.units:
                    self.auto_check_reset()
                    lhv = len(self.active_unit.value)
                    self.changed_since_check = True
                    if event.key == pygame.K_BACKSPACE:
                        if lhv > 0:
                            self.active_unit.value = self.active_unit.value[0:lhv - 1]
                    else:
                        char = event.unicode
                        if len(char) > 0 and ((char in self.digits) or (lhv == 0 and self.allow_dash and char == "-")):
                            if lhv < self.imput_limit:
                                self.active_unit.value += char
                            else:
                                self.active_unit.value = char
                    self.active_unit.update_me = True
                    self.mainloop.redraw_needed[0] = True
            if event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER or
                                                 event.key == pygame.K_TAB or event.key == pygame.K_DOWN):
                if self.all_completed():
                    self.custom_check_result()
                if self.active_unit is not None:
                    self.toggle_active_unit(self.units[(self.active_unit.id + 1) % 5])

            elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
                if self.active_unit is not None:
                    self.toggle_active_unit(self.units[(self.active_unit.id + 4) % 5])

        if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
            self.default_hover(event) 
Example #23
Source File: game120.py    From eduActiv8 with GNU General Public License v3.0 4 votes vote down vote up
def handle(self, event):
        gd.BoardGame.handle(self, event)  # send event handling up
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin]
            for each in self.text_fields:
                if each.rect.topleft[0] < pos[0] < each.rect.topleft[0] + each.rect.width and \
                        each.rect.topleft[1] < pos[1] < each.rect.topleft[1] + each.rect.height:
                    self.toggle_active_fract(each)
            active = self.board.active_ship
            if active == 0:
                self.change_fract_btn(self.response, -1, 0)
            elif active == 1:
                self.change_fract_btn(self.response, 1, 0)
            elif active == 2:
                self.change_fract_btn(self.response, 0, -1)
            elif active == 3:
                self.change_fract_btn(self.response, 0, 1)
            self.auto_check_reset()
        elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
            self.check_result()
        elif event.type == pygame.KEYDOWN:
            self.auto_check_reset()
            lhv = len(self.current_txt)
            self.changed_since_check = True
            if event.key == pygame.K_BACKSPACE:
                if lhv > 0:
                    self.current_txt = self.current_txt[0:lhv - 1]
                    self.active_fract.value = self.current_txt
                self.active_fract.update_me = True
                if len(self.current_txt) > 0:
                    if self.active_fract == self.sm1a:
                        self.response[0] = int(self.active_fract.value)
                    elif self.active_fract == self.sm1b:
                        self.response[1] = int(self.active_fract.value)


            elif event.key == pygame.K_TAB:
                if self.active_fract == self.sm1a:
                    self.toggle_active_fract(self.sm1b)
                else:
                    self.toggle_active_fract(self.sm1a)
            else:
                char = event.unicode
                if char in self.digits:
                    if len(char) > 0 and lhv < 3 and self.active_fract.value != self.qm:
                        self.current_txt += char
                    else:
                        self.current_txt = char

                    self.active_fract.value = self.current_txt

                    if self.active_fract == self.sm1a:
                        self.response[0] = int(self.active_fract.value)
                        if self.response[0] == self.sum_numbers[0]:
                            self.toggle_active_fract(self.sm1b)
                    elif self.active_fract == self.sm1b:
                        self.response[1] = int(self.active_fract.value)
                    self.active_fract.update_me = True

            self.mainloop.redraw_needed[0] = True