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

1
from pydraw import *
2
3
screen = Screen(800, 600, 'Input Example')
4
5
box = Rectangle(screen, 375, 275, 50, 50, Color('gray17'))
6
7
8
def mousedown(button, location):
9
box.color(Color.random())
10
11
12
def mouseup(button, location):
13
box.rotate(1)
14
15
16
def mousedrag(button, location):
17
box.border(Color.random())
18
19
20
def mousemove(location):
21
box.lookat(location)
22
23
24
def keydown(key):
25
if key == 'w':
26
box.move(dy=-5)
27
elif key == 's':
28
box.move(dy=5)
29
if key == 'a':
30
box.move(dx=-5)
31
elif key == 'd':
32
box.move(dx=5)
33
34
35
def keyup(key):
36
if key == 'v':
37
box.clone()
38
39
40
screen.listen()
41
42
fps = 30
43
running = True
44
while running:
45
screen.update()
46
screen.sleep(1 / fps)
Copied!
Last modified 7mo ago
Copy link