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
impl KeybdKey
sourcepub fn bind<F: Fn() + Send + Sync + 'static>(self, callback: F)
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
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();
}
sourcepub fn block_bind<F: Fn() + Send + Sync + 'static>(self, callback: F)
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();
}
sourcepub fn blockable_bind<F: Fn() -> BlockInput + Send + Sync + 'static>(
self,
callback: F
)
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();
}
sourcepub fn bind_all<F: Fn(KeybdKey) + Send + Sync + Clone + 'static>(callback: F)
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();
}
pub fn unbind(self)
source§impl KeybdKey
impl KeybdKey
sourcepub fn is_pressed(self) -> bool
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();
}
sourcepub fn press(self)
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’.
sourcepub fn release(self)
pub fn release(self)
Releases a given KeybdKey
. This means the key would be in the up position.
sourcepub fn is_toggled(self) -> bool
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 IntoEnumIterator for KeybdKey
impl IntoEnumIterator for KeybdKey
type Iterator = KeybdKeyIter
fn iter() -> KeybdKeyIter ⓘ
source§impl PartialEq<KeybdKey> for KeybdKey
impl PartialEq<KeybdKey> for KeybdKey
impl Copy for KeybdKey
impl Eq for KeybdKey
impl StructuralEq for KeybdKey
impl StructuralPartialEq for KeybdKey
Auto Trait Implementations§
impl RefUnwindSafe for KeybdKey
impl Send for KeybdKey
impl Sync for KeybdKey
impl Unpin for KeybdKey
impl UnwindSafe for KeybdKey
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more