from pybevy.input import MouseInput
from pybevy.prelude import *
from pybevy.window import CursorGrabMode, CursorOptions
def grab_mouse(
cursor_options: Single[Mut[CursorOptions]],
mouse: Res[MouseInput],
key: Res[ButtonInput],
) -> None:
for opts in cursor_options:
if mouse.just_pressed(MouseButton.Left()):
opts.visible = False
opts.grab_mode = CursorGrabMode.Locked
if key.just_pressed(KeyCode.Escape):
opts.visible = True
opts.grab_mode = getattr(CursorGrabMode, 'None')
@entrypoint
def main(app: App) -> App:
return app.add_plugins(DefaultPlugins).add_systems(Update, grab_mouse)
if __name__ == "__main__":
main().run()