Crate rebind [−] [src]
rebind
A library for binding input keys to actions, and modifying mouse behaviour. Keys can
be
bound to actions, and then translated during runtime. Keys
are mapped to Actions
using
a HashMap
, so lookup time is constant.
Example
extern crate glutin_window; extern crate piston; extern crate rebind; use glutin_window::GlutinWindow; use piston::event_loop::Events; use piston::input::Event; use piston::input::Button::Keyboard; use piston::input::keyboard::Key; use piston::window::WindowSettings; use rebind::{Action, Builder, Translated}; #[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] enum MyAction { Action1, Action2 } impl Action for MyAction { } fn main() { let window: GlutinWindow = WindowSettings::new("rebind-example", (800, 600)) .build() .expect("Could not create window"); let translator = Builder::<MyAction>::new((800, 600)) .with_mapping(MyAction::Action1, Keyboard(Key::D1)) .with_mapping(MyAction::Action1, Keyboard(Key::A)) .with_mapping(MyAction::Action2, Keyboard(Key::D2)) .with_mapping(MyAction::Action2, Keyboard(Key::B)) .build_translator(); for e in window.events() { if let Event::Input(ref i) = e { if let Some(a) = translator.translate(i) { match a { Translated::Press(MyAction::Action1) => { println!("Action 1 pressed!"); }, Translated::Press(MyAction::Action2) => { println!("Action 2 pressed!"); }, _ => { } } } } } }
Structs
Builder |
Convenience object for constructing an InputMap. |
ButtonTuple |
A three-element tuple of |
ButtonTupleIter |
An iterator over a ButtonTuple. |
InputRebind |
An interface for rebinding keys to actions. This is freely convertable to and from an InputTranslator. |
InputTranslator |
An object which translates piston::input::Input events into input_map::Translated events |
Enums
Translated |
A translated action. |
Traits
Action |
Represents a logical action to be bound to a particular button press, e.g. jump, attack, or move forward. Needs to be hashable, as it is used as a lookup key when rebinding an action to a different button. |