Python Forum
pygame and shift branching?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pygame and shift branching?
#3
Also with KEYUP and KEYDOWN. Mod is pass to the event.
import pygame

class Game:
    def __init__(self, caption, width, height):
        # Basic pygame setup
        pygame.display.set_caption(caption)
        self.rect = pygame.Rect(0, 0, width, height)
        self.surface = pygame.display.set_mode(self.rect.size)
        self.clock = pygame.time.Clock()

    def mainloop(self):
        self.running = True

        while self.running:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.mod & pygame.KMOD_SHIFT:
                        # event.unicode handles shift itself
                        print('Shift', event.unicode)
                    else:
                        print('Key pressed', event.unicode)
                elif event.type == pygame.QUIT:
                    self.running = False

            self.surface.fill(pygame.Color('Darkblue'))

            pygame.display.update()
            self.clock.tick(30)

if __name__ == '__main__':
    pygame.init()
    game = Game('Example', 800, 600)
    game.mainloop()
    pygame.quit()
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
pygame and shift branching? - by MuntyScruntfundle - Feb-23-2019, 12:27 PM
RE: pygame and shift branching? - by metulburr - Feb-23-2019, 12:55 PM
RE: pygame and shift branching? - by Windspar - Feb-23-2019, 01:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Drawn line shift when that surface is copied to another in pygame Leo_Red 4 3,540 Feb-11-2021, 06:33 AM
Last Post: Leo_Red

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020