Struct Keybind

Source
pub struct Keybind { /* private fields */ }

Implementations§

Source§

impl Keybind

Source

pub fn new(keys: &[Keycode]) -> Keybind

Constructs a new Keybind.

§Example
use keybind::{Keybind, Keycode};

let mut keybind = Keybind::new(&[Keycode::LControl, Keycode::G]);
Examples found in repository?
examples/example.rs (line 4)
3fn main() {
4    let mut keybind = Keybind::new(&[Keycode::LControl, Keycode::G]);
5
6    keybind.on_trigger(|| {
7        println!("This will be printed when you press CTRL+G");
8    });
9
10    keybind.wait();
11}
Source

pub fn triggered(&mut self) -> bool

Returns bool if the specific keybind has been triggered

§Example
use keybind::{Keybind, Keycode};

let mut keybind = Keybind::new(&[Keycode::LControl, Keycode::G]);

loop {
    if self.triggered() {
        println!("triggered");
    }
}
Source

pub fn on_trigger<C: Fn() + 'static>(&mut self, callback: C)

Sets provided callback that will be executed on trigger.

§Example
use keybind::{Keybind, Keycode};

let mut keybind = Keybind::new(&[Keycode::LControl, Keycode::G]);

keybind.on_trigger(|| {
    println!("This will be printed when you press CTRL+G");
});
Examples found in repository?
examples/example.rs (lines 6-8)
3fn main() {
4    let mut keybind = Keybind::new(&[Keycode::LControl, Keycode::G]);
5
6    keybind.on_trigger(|| {
7        println!("This will be printed when you press CTRL+G");
8    });
9
10    keybind.wait();
11}
Source

pub fn wait(&mut self)

Starts an infinite loop and calls provided callback when the keybind is triggered.

§Example
use keybind::{Keybind, Keycode};

fn main() {
   let mut keybind = Keybind::new(&[Keycode::LControl, Keycode::G]);

   keybind.on_trigger(|| {
       println!("This will be printed when you press CTRL+G");
   });

   keybind.wait();
}
Examples found in repository?
examples/example.rs (line 10)
3fn main() {
4    let mut keybind = Keybind::new(&[Keycode::LControl, Keycode::G]);
5
6    keybind.on_trigger(|| {
7        println!("This will be printed when you press CTRL+G");
8    });
9
10    keybind.wait();
11}

Auto Trait Implementations§

§

impl Freeze for Keybind

§

impl !RefUnwindSafe for Keybind

§

impl !Send for Keybind

§

impl !Sync for Keybind

§

impl Unpin for Keybind

§

impl !UnwindSafe for Keybind

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.