# Move the box with keyboard and mouse

**URL:** <https://discourse.processing.org/t/move-the-box-with-keyboard-and-mouse/25824>\
**Category:** Processing.py\
**Created:** [November 30, 2020, 7:17am UTC](https://discourse.processing.org/t/move-the-box-with-keyboard-and-mouse/25824 "2020-11-30T07:17:33Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [December 2, 2020, 9:49am UTC](https://discourse.processing.org/t/move-the-box-with-keyboard-and-mouse/25824/10 "2020-12-02T09:49:48Z")

</div>

That’s not much of a plan to work with. Anyhow, here’s a little bullets demo that riffs off some code from [another post](https://discourse.processing.org/t/fixing-bullet-trajectory/9063) –

```auto
class bullet(object):
    def __init__ (self, xpos, ypos, speed):
        self.xpos = xpos
        self.ypos = ypos
        self.speed = speed
        
    def show(self):
        rect(self.xpos, self.ypos, 10, 10)

def setup():
    size(500, 500)
    global bullets
    bullets = []
    
def draw():
    background(0)
    for b in bullets:
        b.xpos -= b.speed
        b.show()

def mousePressed():
    bullets.append(bullet(mouseX, mouseY, -3))
    print(len(bullets)) # print the number of bullets

```

It’ll take some work to integrate. I assume that your bullets must move at angles, so I’d recommend [vectors](https://py.processing.org/reference/PVector.html) over `xpos`/`ypos`/`speed` values. Also, the bullets list just keeps on growing – as you’ll see in the console. The bullets continue to drift through space somewhere beyond the edge of the display window, never expiring.

---

_[View the full topic](https://discourse.processing.org/t/move-the-box-with-keyboard-and-mouse/25824)._
