Module sfml::window::mouse

source ·
Expand description

Access to the real-time state of the mouse.

mouse provides an interface to the state of the mouse.

This module allows users to query the mouse state at any time and directly, without having to deal with a window and its events. Compared to the MouseMoved, MouseButtonPressed and MouseButtonReleased events, mouse can retrieve the state of the cursor and the buttons at any time (you don’t need to store and update a boolean on your side in order to know if a button is pressed or released), and you always get the real state of the mouse, even if it is moved, pressed or released when your window is out of focus and no event is triggered.

Usage example

use sfml::window::{Window, mouse};
use sfml::system::Vector2i;


if mouse::Button::Left.is_pressed() {
    // left click
}

// get global mouse position
let _position = mouse::desktop_position();

// set mouse position relative to a window
window.set_mouse_position(Vector2i::new(100, 200));

Enums

Functions

Get the current position of the mouse in desktop coordinates.
Set the current position of the mouse in desktop coordinates.