Skip to main content

Crate bevy_fix_cursor_unlock_web

Crate bevy_fix_cursor_unlock_web 

Source
Expand description

§Fix Cursor Unlock on Web

crates.io docs.rs

A tiny plugin that fixes Bevy not reporting when the cursor is unlocked on web

§Usage

Just add the plugin, that’s it:

use bevy::prelude::*;
use bevy_fix_cursor_unlock_web::prelude::*;

App::new()
  .add_plugins(DefaultPlugins)
  .add_plugins(FixPointerUnlockPlugin);

Now, Window::cursor_options::grab_mode is automatically set to CursorGrabMode::None for you when unlocking the cursor on web. This fixes https://github.com/bevyengine/bevy/issues/8949

If you want to detect when a cursor was force freed, e.g. when the user presses escape, you can observe the ForceUnlockCursor event. Note that Bevy does not forward the “Escape” key press in this case.

§Compatibility

bevybevy_fix_cursor_unlock_web
0.180.4
0.170.2
0.160.1

Modules§

prelude
Everything you need to fix the cursor unlock on web.

Structs§

FixPointerUnlockPlugin
A tiny plugin that updates all Windows’ CursorOptions::grab_mode when the pointer is unlocked on Web. This fixes https://github.com/bevyengine/bevy/issues/8949. Does nothing on other platforms.
ForceUnlockCursor
Event triggered when the cursor is forced to unlock, e.g. by pressing the Escape key when in fullscreen mode.