Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
bevy-input-sequence
This crate recognizes input sequences from keyboard and gamepad.
Use Cases
- Hotkeys
- Cheat codes
- Developer UI
Installation
Code Examples
Here are some code snippets. These also run as doctests so they do a few things differently than a regular runnable example:
- Use
MinimalPlugins
instead ofDefaultPlugins
, - and call
app.update()
instead ofapp.run()
.
The next section describes the runnable examples that come with the crate.
Run a System on a Key Sequence
Runs a system whenever the user presses the key sequence H I
or "hi" within a
time limit.
use *;
use *;
Send an Event on Key Sequence
Originally bevy-input-sequence
always send an event. You can still do that
with the action::send_event()
.
use *;
use *;
// Define an event
;
// Add event as an key sequence
Send an Event on Gamepad Button Sequence
Gamepads have something that keyboards don't: identity problems. Which player
hit the button sequence may be important to know. So the systems it accepts will
take an input of Gamepad
.
use *;
use *;
// Define an event
;
// Add event as an key sequence
KeySequence creation patterns
KeySequence::new
now returns an implementing of Command
instead of itself.
Therefore, you need to call Commands::add
instead of Commands::spawn
.
use *;
use *;
;
Runnable Examples
keycode
The keycode
example recognizes the key sequences W D S A
and W A S D
and
fires a distinct event.
keymod
The keymod
example recognizes ctrl-W ctrl-D ctrl-S ctrl-A
and fires an event.
gamepad_button
The gamepad_button
example recognizes gamepad buttons North East South West
or Y B A X
on an Xbox controller and fires an event.
multiple_input
The multiple_input
example recognizes gamepad buttons North East South West
,
or Y B A X
on an Xbox controller, or W D S A
on a keyboard and fires an
event.
Note: Either W D S A
will be recognized from the keyboard, or Y B A X
will
be recognized from the controller. But a mixed sequence like W D A X
will not
currently be recognized. If this should be done and how exactly one should do it
are under consideration. Please open an issue or PR if you have thoughts on this.
only_if
The only_if
example recognizes Space
and fires an event if it's in game
mode. The Escape
key toggles the app between menu and game mode. It does this
by only sending the Space
event if it's in game mode.
run_if
The run_if
has the same behavior as only_if
but achieves it differently. It
places the InputSequencePlugin
systems in a system set that is configured to
only run in game mode. Because of this the Escape
key which toggles between
game and menu mode cannot be a KeySequence
.
Compatibility
bevy-input-sequence | bevy |
---|---|
0.3 ~ 0.4.0 | 0.13 |
0.2 | 0.12 |
0.1 | 0.11 |
License
This crate is licensed under the MIT License or the Apache License 2.0.