# Input

{% hint style="info" %}
Remember: In order to register input methods, [`screen.listen()`](https://docs.pydraw.graphics/screen#input) must be called after your methods in your program!
{% endhint %}

## 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()`](https://docs.pydraw.graphics/quick-reference/screen) is called.

## Example

```python
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)
```
