Enum inputbot::KeybdKey

source ·
pub enum KeybdKey {
Show 118 variants BackspaceKey, TabKey, EnterKey, EscapeKey, SpaceKey, PageUpKey, PageDownKey, EndKey, HomeKey, LeftKey, UpKey, RightKey, DownKey, InsertKey, DeleteKey, Numrow0Key, Numrow1Key, Numrow2Key, Numrow3Key, Numrow4Key, Numrow5Key, Numrow6Key, Numrow7Key, Numrow8Key, Numrow9Key, AKey, BKey, CKey, DKey, EKey, FKey, GKey, HKey, IKey, JKey, KKey, LKey, MKey, NKey, OKey, PKey, QKey, RKey, SKey, TKey, UKey, VKey, WKey, XKey, YKey, ZKey, LSuper, RSuper, Numpad0Key, Numpad1Key, Numpad2Key, Numpad3Key, Numpad4Key, Numpad5Key, Numpad6Key, Numpad7Key, Numpad8Key, Numpad9Key, F1Key, F2Key, F3Key, F4Key, F5Key, F6Key, F7Key, F8Key, F9Key, F10Key, F11Key, F12Key, F13Key, F14Key, F15Key, F16Key, F17Key, F18Key, F19Key, F20Key, F21Key, F22Key, F23Key, F24Key, NumLockKey, ScrollLockKey, CapsLockKey, LShiftKey, RShiftKey, LControlKey, RControlKey, LAltKey, RAltKey, BrowserBackKey, BrowserForwardKey, BrowserRefreshKey, VolumeMuteKey, VolumeDownKey, VolumeUpKey, MediaNextTrackKey, MediaPrevTrackKey, MediaStopKey, MediaPlayPauseKey, BackquoteKey, SlashKey, BackslashKey, CommaKey, PeriodKey, MinusKey, QuoteKey, SemicolonKey, LBracketKey, RBracketKey, EqualKey, OtherKey(u64),
}

Variants§

§

BackspaceKey

§

TabKey

§

EnterKey

§

EscapeKey

§

SpaceKey

§

PageUpKey

§

PageDownKey

§

EndKey

§

HomeKey

§

LeftKey

§

UpKey

§

RightKey

§

DownKey

§

InsertKey

§

DeleteKey

§

Numrow0Key

§

Numrow1Key

§

Numrow2Key

§

Numrow3Key

§

Numrow4Key

§

Numrow5Key

§

Numrow6Key

§

Numrow7Key

§

Numrow8Key

§

Numrow9Key

§

AKey

§

BKey

§

CKey

§

DKey

§

EKey

§

FKey

§

GKey

§

HKey

§

IKey

§

JKey

§

KKey

§

LKey

§

MKey

§

NKey

§

OKey

§

PKey

§

QKey

§

RKey

§

SKey

§

TKey

§

UKey

§

VKey

§

WKey

§

XKey

§

YKey

§

ZKey

§

LSuper

§

RSuper

§

Numpad0Key

§

Numpad1Key

§

Numpad2Key

§

Numpad3Key

§

Numpad4Key

§

Numpad5Key

§

Numpad6Key

§

Numpad7Key

§

Numpad8Key

§

Numpad9Key

§

F1Key

§

F2Key

§

F3Key

§

F4Key

§

F5Key

§

F6Key

§

F7Key

§

F8Key

§

F9Key

§

F10Key

§

F11Key

§

F12Key

§

F13Key

§

F14Key

§

F15Key

§

F16Key

§

F17Key

§

F18Key

§

F19Key

§

F20Key

§

F21Key

§

F22Key

§

F23Key

§

F24Key

§

NumLockKey

§

ScrollLockKey

§

CapsLockKey

§

LShiftKey

§

RShiftKey

§

LControlKey

§

RControlKey

§

LAltKey

§

RAltKey

§

BrowserBackKey

§

BrowserForwardKey

§

BrowserRefreshKey

§

VolumeMuteKey

§

VolumeDownKey

§

VolumeUpKey

§

MediaNextTrackKey

§

MediaPrevTrackKey

§

MediaStopKey

§

MediaPlayPauseKey

§

BackquoteKey

§

SlashKey

§

BackslashKey

§

CommaKey

§

PeriodKey

§

MinusKey

§

QuoteKey

§

SemicolonKey

§

LBracketKey

§

RBracketKey

§

EqualKey

§

OtherKey(u64)

Implementations§

source§

impl KeybdKey

source

pub fn bind<F: Fn() + Send + Sync + 'static>(self, callback: F)

Examples found in repository?
examples/autoclicker.rs (lines 21-28)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fn main() {
    // Bind our right mouse button to a function that autoclicks every 30 milliseconds. Hold it down
    // to bake some cookies really fast!
    RightButton.bind(|| {
        while RightButton.is_pressed() {
            LeftButton.press();
            LeftButton.release();

            sleep(Duration::from_millis(30));
        }
    });

    // Bind our Caps Lock key to a function that toggles autoclicking. Go AFK and bake some
    // cookies really fast without hurting your hands!
    CapsLockKey.bind(move || {
        while CapsLockKey.is_toggled() {
            LeftButton.press();
            LeftButton.release();

            sleep(Duration::from_millis(30));
        }
    });

    // Call this to start listening for bound inputs.
    inputbot::handle_input_events();
}
More examples
Hide additional examples
examples/key_sequences.rs (lines 17-19)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    // If you are on Linux, you may wish to call this function first to avoid a startup delay when
    // the fake device is created. Otherwise, your first input event - if it is a key sequence - may
    // have missing characters.
    //     inputbot::init_device();

    // Bind our Backquote key (`, ~) to a function that types out the string "Hello, world!".
    // You must remember to call the `.send()` method on the KeySequence after creating it.
    // You could explicitly define the KeySequence ahead of time and send it later like so:
    //      let seq: KeySequence = KeySequence("Hello, world!");
    //      seq.send();
    BackquoteKey.bind(|| {
        KeySequence("Hello, world!").send();
    });

    // Call this to start listening for bound inputs.
    inputbot::handle_input_events();
}
examples/move_mouse.rs (lines 14-19)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    // Bind our 1 key to a function that moves the mouse absolute to your monitors. Note: if you
    // have multiple monitors, 0, 0 might be not where you're expecting. If we wanted to get the
    // absolute position of your primary (or a specific) monitor, we would need to bring in extra
    // libraries.
    Numrow1Key.bind(|| {
        for x in 0..=600 {
            MouseCursor::move_abs(x as i32, 300);
            sleep(Duration::from_millis(1));
        }
    });

    // Bind our 2 key to a function that moves the mouse relative to its current position.
    // This will be 100 pixels over and 100 pixels down.
    Numrow2Key.bind(|| {
        MouseCursor::move_rel(100, 100);
        sleep(Duration::from_millis(1));
    });

    // Call this to start listening for bound inputs.
    inputbot::handle_input_events();
}
source

pub fn block_bind<F: Fn() + Send + Sync + 'static>(self, callback: F)

Examples found in repository?
examples/blockable_binds.rs (line 19)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    // Block the A key when left shift is held. Note: callbacks for blockable binds won't be
    // executed in new threads, so for long-running processes create new threads inside the callback
    // if needed.
    AKey.blockable_bind(|| {
        if LShiftKey.is_pressed() {
            Block
        } else {
            DontBlock
        }
    });

    // Block the K key when left shift is held.
    KKey.block_bind(|| ());

    // Call this to start listening for bound inputs.
    inputbot::handle_input_events();
}
source

pub fn blockable_bind<F: Fn() -> BlockInput + Send + Sync + 'static>( self, callback: F )

Examples found in repository?
examples/blockable_binds.rs (lines 10-16)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    // Block the A key when left shift is held. Note: callbacks for blockable binds won't be
    // executed in new threads, so for long-running processes create new threads inside the callback
    // if needed.
    AKey.blockable_bind(|| {
        if LShiftKey.is_pressed() {
            Block
        } else {
            DontBlock
        }
    });

    // Block the K key when left shift is held.
    KKey.block_bind(|| ());

    // Call this to start listening for bound inputs.
    inputbot::handle_input_events();
}
source

pub fn bind_all<F: Fn(KeybdKey) + Send + Sync + Clone + 'static>(callback: F)

Examples found in repository?
examples/bind_all.rs (lines 8-13)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    // Bind all keys to a common callback event.
    KeybdKey::bind_all(|event| {
        match inputbot::from_keybd_key(event) {
            Some(c) => println!("{c}"),
            None => println!("Unregistered Key"),
        };
    });

    // Bind all mouse buttons to a common callback event.
    MouseButton::bind_all(|event| {
        println!("{:?}", event);
    });

    // Call this to start listening for bound inputs.
    inputbot::handle_input_events();
}
source

pub fn unbind(self)

source§

impl KeybdKey

source

pub fn is_pressed(self) -> bool

Returns true if a given KeybdKey is currently pressed (in the down position).

Examples found in repository?
examples/blockable_binds.rs (line 11)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    // Block the A key when left shift is held. Note: callbacks for blockable binds won't be
    // executed in new threads, so for long-running processes create new threads inside the callback
    // if needed.
    AKey.blockable_bind(|| {
        if LShiftKey.is_pressed() {
            Block
        } else {
            DontBlock
        }
    });

    // Block the K key when left shift is held.
    KKey.block_bind(|| ());

    // Call this to start listening for bound inputs.
    inputbot::handle_input_events();
}
source

pub fn press(self)

Presses a given KeybdKey. Note: this means the key will remain in the down position. You must manually call release to create a full ‘press’.

source

pub fn release(self)

Releases a given KeybdKey. This means the key would be in the up position.

source

pub fn is_toggled(self) -> bool

Returns true if a keyboard key which supports toggling (ScrollLock, NumLock, CapsLock) is on.

Examples found in repository?
examples/autoclicker.rs (line 22)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fn main() {
    // Bind our right mouse button to a function that autoclicks every 30 milliseconds. Hold it down
    // to bake some cookies really fast!
    RightButton.bind(|| {
        while RightButton.is_pressed() {
            LeftButton.press();
            LeftButton.release();

            sleep(Duration::from_millis(30));
        }
    });

    // Bind our Caps Lock key to a function that toggles autoclicking. Go AFK and bake some
    // cookies really fast without hurting your hands!
    CapsLockKey.bind(move || {
        while CapsLockKey.is_toggled() {
            LeftButton.press();
            LeftButton.release();

            sleep(Duration::from_millis(30));
        }
    });

    // Call this to start listening for bound inputs.
    inputbot::handle_input_events();
}

Trait Implementations§

source§

impl Clone for KeybdKey

source§

fn clone(&self) -> KeybdKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for KeybdKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<KeybdKey> for u64

source§

fn from(key: KeybdKey) -> u64

Converts to this type from the input type.
source§

impl From<u64> for KeybdKey

source§

fn from(code: u64) -> KeybdKey

Converts to this type from the input type.
source§

impl Hash for KeybdKey

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl IntoEnumIterator for KeybdKey

source§

impl PartialEq<KeybdKey> for KeybdKey

source§

fn eq(&self, other: &KeybdKey) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for KeybdKey

source§

impl Eq for KeybdKey

source§

impl StructuralEq for KeybdKey

source§

impl StructuralPartialEq for KeybdKey

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.