Skip to content

mouseIsPressed()

A Boolean system variable that's true if the mouse is pressed and false if not.

Examples

mouseIsPressed example 1

function setup()
  size(100, 100)

  describe(
    'A gray square with the word "false" at its center. The word changes to "true" when the user presses a mouse button.'
  )
end

function draw()
  background(200)
  fill(0)

  -- Style the text.
  textAlign(CENTER)
  textSize(16)

  -- Display the mouseIsPressed variable.
  text(mouseIsPressed, 25, 50)
end

mouseIsPressed example 2

function setup()
  size(100, 100)

  describe(
    'A gray square with a white square at its center. The inner square turns black when the user presses the mouse.'
  )
end

function draw()
  background(200)

  -- Style the square.
  if mouseIsPressed == true then
    fill(0)
  else 
    fill(255)
  end

  -- Draw the square.
  square(25, 25, 50)
end

Syntax

mouseIsPressed

Returns

Boolean: true or false.