Knowledge Base‎ > ‎Programming‎ > ‎Python‎ > ‎Python Reference‎ > ‎Python Reference‎ > ‎


mouse.button - tells what mouse button is pressed
mouse.pressed - tells whether a mouse button is pressed
mouse.x - current x position of the mouse
mouse.y - current y position of the mouse


A function that is called whenever the mouse is clicked - likewise the other functions below are also called when the mouse is dragged (clicked on and moved) or moved. Inside any of these functions you can then check to see where the mouse is (using mouse.x and mouse.y) or what buttons are pressed.

# Click within the image to change 
# the value of the rectangle after
# after the mouse has been clicked

value = 0

def draw():
  rect(25, 25, 50, 50)

def mouseClicked():
  global value
  if value == 0:
    value = 255
    value = 0

Called whenever the mouse is dragged (mouse button clicked and held down while moved).

Called whenever the mouse is moved