kitten/mouse

This module contains a few simple functions to work with mouse input. These are intended for use inside your update function. The custom Button types ensures that you can only check for real buttons and prevents misspellings.

Example:

let new_pos = case mouse.was_pressed(mouse.LMB) && mouse.pos().x >=. 0.0 {
  True -> pos |> vec2.add(Vec2(1.0, 0.0))
  False -> pos
}

Types

pub type Button {
  LMB
  MMB
  RMB
}

Constructors

  • LMB
  • MMB
  • RMB

Functions

pub fn is_down(button: Button) -> Bool

Returns True if the mouse button was pressed in the time since the last frame, but has not yet been released, and False otherwise. Unless you specifically want the player to hold the mouse down for some time, you might be better off using the was_pressed and was_released functions.

pub fn pos() -> Vec2

Returns the position of the mouse in world coordinates.

pub fn was_pressed(button: Button) -> Bool

Returns True if the mouse button was pressed in the time since the last frame, and False otherwise.

pub fn was_released(button: Button) -> Bool

Returns True if the mouse button was released in the time since the last frame, and False otherwise.

Search Document