Python pyglet.window.key.RIGHT Examples
The following are 30
code examples of pyglet.window.key.RIGHT().
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
pyglet.window.key
, or try the search function
.
Example #1
Source File: interactive_game.py From safelife with Apache License 2.0 | 6 votes |
def pyglet_key_down(self, symbol, modifier, repeat_in=0.3): from pyglet.window import key self.last_key_down = symbol self.last_key_modifier = modifier self.next_key_repeat = time.time() + repeat_in is_ascii = 27 <= symbol < 255 char = { key.LEFT: KEYS.LEFT_ARROW, key.RIGHT: KEYS.RIGHT_ARROW, key.UP: KEYS.UP_ARROW, key.DOWN: KEYS.DOWN_ARROW, key.ENTER: '\r', key.RETURN: '\r', key.BACKSPACE: chr(127), }.get(symbol, chr(symbol) if is_ascii else None) if not char: # All other characters don't count as a key press # (e.g., function keys, modifier keys, etc.) return if modifier & key.MOD_SHIFT: char = char.upper() self.set_needs_display() self.handle_input(char)
Example #2
Source File: __init__.py From flappy-bird-py with GNU General Public License v2.0 | 6 votes |
def _get_mouse_button_and_modifiers(ev): button = EventMouseButton() carbon.GetEventParameter(ev, kEventParamMouseButton, typeMouseButton, c_void_p(), sizeof(button), c_void_p(), byref(button)) if button.value == 1: button = mouse.LEFT elif button.value == 2: button = mouse.RIGHT elif button.value == 3: button = mouse.MIDDLE else: button = None modifiers = c_uint32() carbon.GetEventParameter(ev, kEventParamKeyModifiers, typeUInt32, c_void_p(), sizeof(modifiers), c_void_p(), byref(modifiers)) return button, CarbonWindow._map_modifiers(modifiers.value)
Example #3
Source File: player.py From learning-python with MIT License | 6 votes |
def update(self, dt): # Do all the normal physics stuff super(Player, self).update(dt) if self.key_handler[key.LEFT]: self.rotation -= self.rotate_speed * dt if self.key_handler[key.RIGHT]: self.rotation += self.rotate_speed * dt if self.key_handler[key.UP]: # Note: pyglet's rotation attributes are in "negative degrees" angle_radians = -math.radians(self.rotation) force_x = math.cos(angle_radians) * self.thrust * dt force_y = math.sin(angle_radians) * self.thrust * dt self.velocity_x += force_x self.velocity_y += force_y # If thrusting, update the engine sprite self.engine_sprite.rotation = self.rotation self.engine_sprite.x = self.x self.engine_sprite.y = self.y self.engine_sprite.visible = True else: # Otherwise, hide it self.engine_sprite.visible = False
Example #4
Source File: player.py From pyglet with BSD 3-Clause "New" or "Revised" License | 6 votes |
def update(self, dt): # Do all the normal physics stuff super(Player, self).update(dt) if self.key_handler[key.LEFT]: self.rotation -= self.rotate_speed * dt if self.key_handler[key.RIGHT]: self.rotation += self.rotate_speed * dt if self.key_handler[key.UP]: # Note: pyglet's rotation attributes are in "negative degrees" angle_radians = -math.radians(self.rotation) force_x = math.cos(angle_radians) * self.thrust * dt force_y = math.sin(angle_radians) * self.thrust * dt self.velocity_x += force_x self.velocity_y += force_y # If thrusting, update the engine sprite self.engine_sprite.rotation = self.rotation self.engine_sprite.x = self.x self.engine_sprite.y = self.y self.engine_sprite.visible = True else: # Otherwise, hide it self.engine_sprite.visible = False
Example #5
Source File: player.py From pyglet with BSD 3-Clause "New" or "Revised" License | 6 votes |
def update(self, dt): # Do all the normal physics stuff super(Player, self).update(dt) if self.key_handler[key.LEFT]: self.rotation -= self.rotate_speed * dt if self.key_handler[key.RIGHT]: self.rotation += self.rotate_speed * dt if self.key_handler[key.UP]: # Note: pyglet's rotation attributes are in "negative degrees" angle_radians = -math.radians(self.rotation) force_x = math.cos(angle_radians) * self.thrust * dt force_y = math.sin(angle_radians) * self.thrust * dt self.velocity_x += force_x self.velocity_y += force_y # If thrusting, update the engine sprite self.engine_sprite.rotation = self.rotation self.engine_sprite.x = self.x self.engine_sprite.y = self.y self.engine_sprite.visible = True else: # Otherwise, hide it self.engine_sprite.visible = False
Example #6
Source File: __init__.py From flappy-bird-py with GNU General Public License v2.0 | 6 votes |
def _get_mouse_button_and_modifiers(ev): button = EventMouseButton() carbon.GetEventParameter(ev, kEventParamMouseButton, typeMouseButton, c_void_p(), sizeof(button), c_void_p(), byref(button)) if button.value == 1: button = mouse.LEFT elif button.value == 2: button = mouse.RIGHT elif button.value == 3: button = mouse.MIDDLE else: button = None modifiers = c_uint32() carbon.GetEventParameter(ev, kEventParamKeyModifiers, typeUInt32, c_void_p(), sizeof(modifiers), c_void_p(), byref(modifiers)) return button, CarbonWindow._map_modifiers(modifiers.value)
Example #7
Source File: player.py From pyglet with BSD 3-Clause "New" or "Revised" License | 6 votes |
def update(self, dt): # Do all the normal physics stuff super(Player, self).update(dt) if self.key_handler[key.LEFT]: self.rotation -= self.rotate_speed * dt if self.key_handler[key.RIGHT]: self.rotation += self.rotate_speed * dt if self.key_handler[key.UP]: angle_radians = -math.radians(self.rotation) force_x = math.cos(angle_radians) * self.thrust * dt force_y = math.sin(angle_radians) * self.thrust * dt self.velocity_x += force_x self.velocity_y += force_y # If thrusting, update the engine sprite self.engine_sprite.rotation = self.rotation self.engine_sprite.x = self.x self.engine_sprite.y = self.y self.engine_sprite.visible = True else: # Otherwise, hide it self.engine_sprite.visible = False
Example #8
Source File: car_racing.py From ia-course with MIT License | 5 votes |
def key_press(k, mod): global restart if k==0xff0d: restart = True if k==key.LEFT: a[0] = -1.0 if k==key.RIGHT: a[0] = +1.0 if k==key.UP: a[1] = +1.0 if k==key.DOWN: a[2] = +0.8 # set 1.0 for wheels to block to zero rotation
Example #9
Source File: policy.py From marl_transfer with MIT License | 5 votes |
def key_release(self, k, mod): if k==key.LEFT: self.move[0] = False if k==key.RIGHT: self.move[1] = False if k==key.UP: self.move[2] = False if k==key.DOWN: self.move[3] = False
Example #10
Source File: car_racing.py From ia-course with MIT License | 5 votes |
def key_release(k, mod): if k==key.LEFT and a[0]==-1.0: a[0] = 0 if k==key.RIGHT and a[0]==+1.0: a[0] = 0 if k==key.UP: a[1] = 0 if k==key.DOWN: a[2] = 0
Example #11
Source File: player.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_key_press(self, symbol, modifiers): if symbol == key.UP: self.keys['up'] = True elif symbol == key.LEFT: self.keys['left'] = True elif symbol == key.RIGHT: self.keys['right'] = True
Example #12
Source File: player.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_key_release(self, symbol, modifiers): if symbol == key.UP: self.keys['up'] = False elif symbol == key.LEFT: self.keys['left'] = False elif symbol == key.RIGHT: self.keys['right'] = False
Example #13
Source File: astraea.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_key_release(self, symbol, modifiers): if symbol == key.LEFT or symbol == key.RIGHT: self.value = not self.value self.text.text = self.get_label() self.toggle_func(self.value) if enable_sound: bullet_sound.play()
Example #14
Source File: astraea.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_key_release(self, symbol, modifiers): global difficulty if symbol == key.LEFT: difficulty -= 1 elif symbol == key.RIGHT: difficulty += 1 difficulty = min(max(difficulty, 0), MAX_DIFFICULTY) self.text.text = self.get_label() if symbol in (key.LEFT, key.RIGHT) and enable_sound: bullet_sound.play()
Example #15
Source File: media_player.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_key_press(self, symbol, modifiers): if symbol == key.SPACE: self.on_play_pause() elif symbol == key.ESCAPE: self.dispatch_event('on_close') elif symbol == key.LEFT: self.player.seek(0) elif symbol == key.RIGHT: self.player.next_source()
Example #16
Source File: test_window_settings.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_key_press(self, symbol, modifiers): x, y = self.w.get_location() if symbol == key.LEFT: x -= 10 if symbol == key.RIGHT: x += 10 if symbol == key.UP: y -= 10 if symbol == key.DOWN: y += 10 self.w.set_location(x, y) print('Window location set to %dx%d.' % (x, y)) print('Window location now: %dx%d.' % self.w.get_location()) self.assertSequenceEqual((x, y), self.w.get_location())
Example #17
Source File: test_window_settings.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_key_press(self, symbol, modifiers): names = [ self.w.CURSOR_DEFAULT, self.w.CURSOR_CROSSHAIR, self.w.CURSOR_HAND, self.w.CURSOR_HELP, self.w.CURSOR_NO, self.w.CURSOR_SIZE, self.w.CURSOR_SIZE_UP, self.w.CURSOR_SIZE_UP_RIGHT, self.w.CURSOR_SIZE_RIGHT, self.w.CURSOR_SIZE_DOWN_RIGHT, self.w.CURSOR_SIZE_DOWN, self.w.CURSOR_SIZE_DOWN_LEFT, self.w.CURSOR_SIZE_LEFT, self.w.CURSOR_SIZE_UP_LEFT, self.w.CURSOR_SIZE_UP_DOWN, self.w.CURSOR_SIZE_LEFT_RIGHT, self.w.CURSOR_TEXT, self.w.CURSOR_WAIT, self.w.CURSOR_WAIT_ARROW, ] if symbol == key.ESCAPE: self.w.on_close() if symbol == key.RIGHT: self.i = (self.i + 1) % len(names) elif symbol == key.LEFT: self.i = (self.i - 1) % len(names) cursor = self.w.get_system_mouse_cursor(names[self.i]) self.w.set_mouse_cursor(cursor) print('Set cursor to "%s"' % names[self.i]) return True
Example #18
Source File: __init__.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _event_rbuttondown(self, msg, wParam, lParam): return self._event_mousebutton( 'on_mouse_press', mouse.RIGHT, lParam)
Example #19
Source File: __init__.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _event_rbuttonup(self, msg, wParam, lParam): return self._event_mousebutton( 'on_mouse_release', mouse.RIGHT, lParam)
Example #20
Source File: __init__.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _event_motionnotify(self, ev): # Window motion looks for drags that are outside the view but within # the window. buttons = 0 if ev.xmotion.state & xlib.Button1MotionMask: buttons |= mouse.LEFT if ev.xmotion.state & xlib.Button2MotionMask: buttons |= mouse.MIDDLE if ev.xmotion.state & xlib.Button3MotionMask: buttons |= mouse.RIGHT if buttons: # Drag event x = ev.xmotion.x - self._view_x y = self._height - (ev.xmotion.y - self._view_y) if self._mouse_in_window: dx = x - self._mouse_x dy = y - self._mouse_y else: dx = dy = 0 self._mouse_x = x self._mouse_y = y modifiers = self._translate_modifiers(ev.xmotion.state) self.dispatch_event('on_mouse_drag', x, y, dx, dy, buttons, modifiers)
Example #21
Source File: policy.py From malib with MIT License | 5 votes |
def key_press(self, k, mod): if k == key.LEFT: self.move[0] = True if k == key.RIGHT: self.move[1] = True if k == key.UP: self.move[2] = True if k == key.DOWN: self.move[3] = True
Example #22
Source File: policy.py From malib with MIT License | 5 votes |
def key_release(self, k, mod): if k == key.LEFT: self.move[0] = False if k == key.RIGHT: self.move[1] = False if k == key.UP: self.move[2] = False if k == key.DOWN: self.move[3] = False
Example #23
Source File: policy.py From multiagent-gail with MIT License | 5 votes |
def key_press(self, k, mod): if k==key.LEFT: self.move[0] = True if k==key.RIGHT: self.move[1] = True if k==key.UP: self.move[2] = True if k==key.DOWN: self.move[3] = True
Example #24
Source File: policy.py From multiagent-gail with MIT License | 5 votes |
def key_release(self, k, mod): if k==key.LEFT: self.move[0] = False if k==key.RIGHT: self.move[1] = False if k==key.UP: self.move[2] = False if k==key.DOWN: self.move[3] = False
Example #25
Source File: player_agent.py From playground with Apache License 2.0 | 5 votes |
def __init__(self, character=characters.Bomber, agent_control='arrows'): super(PlayerAgent, self).__init__(character) ## # @NOTE: DO NOT move this import outside the constructor. It will # not work in headless environments like a Docker container # and prevents Pommerman from running. # from pyglet.window import key controls = { 'arrows': { key.UP: 1, key.DOWN: 2, key.LEFT: 3, key.RIGHT: 4, key.SPACE: 5, key.M: 6 # In Pommerman, this will freeze the game. }, 'wasd': { key.W: 1, key.S: 2, key.A: 3, key.D: 4, key.E: 5, key.Q: 6 # In Pommerman, this will freeze the game. } } assert agent_control in controls, "Unknown control: {}".format( agent_control) self._key2act = controls[agent_control] self._action_q = [] self._keystate = {}
Example #26
Source File: car_racing.py From DQN-DDPG_Stock_Trading with MIT License | 5 votes |
def key_press(k, mod): global restart if k==0xff0d: restart = True if k==key.LEFT: a[0] = -1.0 if k==key.RIGHT: a[0] = +1.0 if k==key.UP: a[1] = +1.0 if k==key.DOWN: a[2] = +0.8 # set 1.0 for wheels to block to zero rotation
Example #27
Source File: car_racing.py From DQN-DDPG_Stock_Trading with MIT License | 5 votes |
def key_release(k, mod): if k==key.LEFT and a[0]==-1.0: a[0] = 0 if k==key.RIGHT and a[0]==+1.0: a[0] = 0 if k==key.UP: a[1] = 0 if k==key.DOWN: a[2] = 0
Example #28
Source File: policy.py From marl_transfer with MIT License | 5 votes |
def key_press(self, k, mod): if k==key.LEFT: self.move[0] = True if k==key.RIGHT: self.move[1] = True if k==key.UP: self.move[2] = True if k==key.DOWN: self.move[3] = True
Example #29
Source File: tutorial2.py From ratcave with MIT License | 5 votes |
def move_camera(dt): camera_speed = 3 if keys[key.LEFT]: scene.camera.position.x -= camera_speed * dt if keys[key.RIGHT]: scene.camera.position.x += camera_speed * dt
Example #30
Source File: astraea.py From flappy-bird-py with GNU General Public License v2.0 | 5 votes |
def on_key_press(self, symbol, modifiers): if symbol == key.LEFT or symbol == key.RIGHT: self.value = not self.value self.text.text = self.get_label() self.toggle_func(self.value) if enable_sound: bullet_sound.play()