Skip to content

focused()

A Boolean variable that's true if the window is focused and false if not.

Note: The window can only receive input if it's focused.

Examples

focused example 1

-- Open this example in two separate browser
-- windows placed side-by-side to demonstrate.

function setup()
  size(100, 100)

  describe('A square changes color from green to red when the window is out of focus.')
end

function draw()
  -- Change the background color
  -- when the window
  -- goes in/out of focus.
  if focused then
    background(0, 255, 0)
  else 
    background(255, 0, 0)
  end
end


This reference page contains content adapted from p5.js and Processing by p5.js Contributors and Processing Foundation, licensed under CC BY-NC-SA 4.0.