Input

The Quick Reference for Input just lists all methods available to be registered for input.

Remember: In order to register input methods, screen.listen() must be called after your methods in your program!

All Input Methods

  • mousedown | When the mouse is pressed or is held, this will be called

  • mouseup | When the mouse is released this is called

  • mousedrag | When the mouse is dragged, this is called anytime the mouse moves and is held.

  • mousemove | When the mouse moves, this method is called.

  • keydown | When a key is pressed or is currently being held, this is called

  • keyup | When a key is released this is called

  • exit | Called when the Screen is abruptly closed or screen.exit() is called.

Example

from pydraw import *

screen = Screen(800, 600, 'Input Example')

box = Rectangle(screen, 375, 275, 50, 50, Color('gray17'))

# another cool thing to know is the 'button' parameter is optional!
def mousedown(location, button):
    box.color(Color.random())


def mouseup(location, button):
    box.rotate(1)


def mousedrag(location, button):
    box.border(Color.random())


def mousemove(location):
    box.lookat(location)


def keydown(key):
    if key == 'w':
        box.move(dy=-5)
    elif key == 's':
        box.move(dy=5)
    if key == 'a':
        box.move(dx=-5)
    elif key == 'd':
        box.move(dx=5)


def keyup(key):
    if key == 'v':
        box.clone()


screen.listen()

fps = 30
running = True
while running:
    screen.update()
    screen.sleep(1 / fps)

Last updated