10 examples of 'pygame.key.get_pressed' in Python

Every line of 'pygame.key.get_pressed' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
95def checkForKeyPress():
96 if len(pygame.event.get(QUIT)) > 0:
97 terminate()
98
99 keyUpEvents = pygame.event.get(KEYUP)
100 if len(keyUpEvents) == 0:
101 return None
102 if keyUpEvents[0].key == K_ESCAPE:
103 terminate()
104 return keyUpEvents[0].key
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

146def key_down(self, key):
147 if key in self.map:
148 self.velocity = V2((3 / self.scale, 0) if key in self.map[:2] else (0, 3 / self.scale)).elementwise() * (
149 (self.map.index(key) not in (1, 2)) * 2 - 1)
81def pressTest(self, key):
82 print( "-> Pressing " + key.upper() )
128def _key_pressed(self, keycode):
129 movement_bindings = {
130 curses.KEY_UP: ( 1, 0),
131 curses.KEY_DOWN: (-1, 0),
132 curses.KEY_LEFT: ( 0, 1),
133 curses.KEY_RIGHT: ( 0, -1),
134 }
135 speed_bindings = {
136 ord(' '): (0, 0),
137 }
138 if keycode in movement_bindings:
139 acc = movement_bindings[keycode]
140 ok = False
141 if acc[0]:
142 linear = self._linear + acc[0]
143 if abs(linear) <= self._num_steps:
144 self._linear = linear
145 ok = True
146 if acc[1]:
147 angular = self._angular + acc[1]
148 if abs(angular) <= self._num_steps:
149 self._angular = angular
150 ok = True
151 if not ok:
152 self._interface.beep()
153 elif keycode in speed_bindings:
154 acc = speed_bindings[keycode]
155 # Note: bounds aren't enforced here!
156 if acc[0] is not None:
157 self._linear = acc[0]
158 if acc[1] is not None:
159 self._angular = acc[1]
160
161 elif keycode == ord('q'):
162 rospy.signal_shutdown('Bye')
163 else:
164 return False
165
166 return True
92def on_key_press(self, k, mod):
93 numbers = [key._1, key._2, key._3, key._4, key._5,
94 key._6, key._7, key._8, key._9, key._0 ]
95 if k == key.T:
96 # track if the user wants to translate origin to the current
97 # skeleton position
98 # if you run two walk left animations without translation
99 # you will see a player move left, go to the origin and move
100 # left again.
101 # if you use translation, the player will just move left twice
102 # as far
103 self.translate = not self.translate
104 if k == key.F:
105 # track if the user wants to run the animation normal or flipped
106 # if the animation is a guy walking left, when flipped it will
107 # walk right
108 self.flipped = not self.flipped
109 self.skin.flip()
110
111 if k in numbers:
112 # find which animation the user wants to run
113 n = numbers.index(k)
114 if n < len(self.anims):
115 # kill current animations
116 self.skin.stop()
117 anim = self.anims[n]
118 # if we want to run the animation flipped, we create
119 # the flipped version
120 if self.flipped:
121 anim = anim.flipped()
122 # we run the animation on the skin using the Animate action.
123 # remember that Animate is a cocos action, so you can do
124 # any action stuff you want with them.
125 # you just have to say which animation you want to use
126 # and what kind of translation
127 self.skin.do( Animate( anim , recenter_x=self.translate ) )
85def key_right(self):
86 self.PLAYER.PLAYER_POS[0] += self.movement
87 self.PLAYER.DIRECTION = 'r'
88
89 self.PLAYER.SPRITE_POS = pygame.image.load(r_images[self.counter])
90 self.counter = (self.counter + 1) % len(r_images)
91
92 if self.PLAYER.TRANSFORM:
93 self.PLAYER.WOLF = pygame.image.load(wolf_r_images[self.wolf_counter_lr])
94 self.wolf_counter_lr = (self.wolf_counter_lr + 1) % len(wolf_r_images)
164def pressAndHold(*args):
165 '''
166 press and hold. Do NOT release.
167 accepts as many arguments as you want.
168 e.g. pressAndHold('left_arrow', 'a','b').
169 '''
170 for i in args:
171 win32api.keybd_event(VK_CODE[i], 0, 0, 0)
172 time.sleep(.05)
91@staticmethod
92def joy_key(key, inlist=True, testmode=True):
93 """
94 Create a pygame joy controller key event.
95
96 :param key: Key to press
97 :type key: bool
98 :param inlist: Return event in a list
99 :type inlist: bool
100 :param testmode: Key event is in test mode
101 :type testmode: bool
102 :return: Event
103 :rtype: pygame.event.Event
104 """
105 event_obj = pygame.event.Event(pygame.JOYHATMOTION,
106 {'value': key,
107 'test': testmode
108 })
109 if inlist:
110 event_obj = [event_obj]
111 return event_obj
4def quit_or_esc() -> bool:
5 """
6 Check if the quit event is triggered or the ESC key is pressed.
7 """
8 for event in pygame.event.get():
9 if event.type == pygame.QUIT or \
10 (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
11 return True
12 return False
122def on_key_press(self, key, modifiers):
123 """
124 Called whenever the mouse moves.
125 """
126 if key == arcade.key.UP:
127 self.player.change_y = MOVEMENT_SPEED
128 elif key == arcade.key.DOWN:
129 self.player.change_y = -MOVEMENT_SPEED
130 elif key == arcade.key.LEFT:
131 self.player.change_x = -MOVEMENT_SPEED
132 elif key == arcade.key.RIGHT:
133 self.player.change_x = MOVEMENT_SPEED

Related snippets