Cross-platform (Windows & Linux) library for simulating keyboard/mouse input events and registering global input device...

Cross-platform (Windows & Linux) library for simulating keyboard/mouse input events and registering global input device event handlers

InputBot

Cross-platform (Windows & Linux) library for simulating keyboard/mouse input events and registering global input device event handlers.

Allows writing automation programs that collapse long action-sequences into single key-presses.

Usage sample

use inputbot::{KeybdKey::*, MouseButton::*, *};
use std::{thread::sleep, time::Duration};

fn main() {
    // Autorun for videogames.
    NumLockKey.bind(|| {
        while NumLockKey.is_toggled() {
            LShiftKey.press();
            WKey.press();
            sleep(Duration::from_millis(50));
            WKey.release();
            LShiftKey.release();
        }
    });

    // Rapidfire for videogames.
    RightButton.bind(|| {
        while RightButton.is_pressed() {
            LeftButton.press();
            sleep(Duration::from_millis(50));
            LeftButton.release();
        }
    });

    // Send a key sequence.
    RKey.bind(|| KeySequence("Sample text").send());

    // Move mouse.
    QKey.bind(|| MouseCursor::move_rel(10, 10));

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

Build Dependencies

Debian or Ubuntu based distros

  • libx11-dev
  • libxtst-dev
  • libudev-dev

Runtime Dependencies

Debian or Ubuntu based distros

  • libinput-dev

Note: libinput requires InputBot to be run with sudo on Linux - sudo ./target/debug/<program name>.

Issues

Collection of the latest Issues

Neutron3529

Neutron3529

0

This error is generated when I scroll my mouse, it seems that there is a bug in input-0.6.0, I update input to 0.7.1 and the bug solved.

(I also edited line 201 of mod.rs to make rustc happy.)

besides, there are 6 warnings after update:

I have no idea of those code, since they do not bother my program.

Corallus-Caninus

Corallus-Caninus

0

Cannot bind to right keys

right keys in linux have 0xe0 prepended to them. I cant seem to get is_pressed() to address the bitmap appropriately for scancodes that have a sequence greater than one.

at least the following keys are missing from the enumeration: right ctrl numpad enter (KP_Enter vs Return in xmodmap -pke)

I'm working on it but got stuck and thought it worth posting thanks.

Corallus-Caninus

Corallus-Caninus

0

Some of the enumerations are not accessible.

For example: this means certain actions such as Numpad7Key.is_toggled() work but HomeKey.is_toggled() doesnt.

I have patched this on my branch specifically for another project but have not been able to create an upstream fix yet nor do I plan to at this time.

Corallus-Caninus

Corallus-Caninus

0

I cant seem to get OtherKey() to work with the enumeration. Ive tried the hex code returned from xev and the uint returned from showkey. Is there further documentation or a working example?

Thanks.

shubhamvasaikar

shubhamvasaikar

0

First of all thank you for the efforts you put into this. I am trying to write an application that will send a key sequence when the F2key is pressed. However this string is not known during compile time and I generate it at run time. For this I am using the lazy_static macro to initialize the string during run time. Here's what my code looks like:

The println line works fine for this, but the KeySequence line does not. I have verified that the binding works well if I just pass it a string literal, however I do not get any output when I pass the static MY_STRING in this way.

The binding is probably working fine, as the program stops and wait instead of just exiting. Other bindings also function. However, it seems that nothing is getting passed to the send() method when ran this way. Any ideas why this might be happening? Thank you.

Edit: I'm running this on a RHEL-8 machine.

aaronleopold

aaronleopold

6

I'll try and work on implementing a solution compatible with MacOS over the next few months, and I'll post any updates / concerns over on this issue.

My current plan is to create some rust bindings around a C file that would call apple's native api for event handling.

joaochris

joaochris

1

How do I run this on windows? I want to configure the click on a player within a program. I don't know anything about programming.

skkeeper

skkeeper

2

Hi, first of all thanks for your work on this. I've starting to mess a bit with Rust and was trying to simulate the MEDIA KEY PLAY/PAUSE press on Windows. I might be messing something up but this is the code I'm trying to use as an example:

Running this code seems to cause the "g" key to be pressed instead of VK_MEDIA_PLAY_PAUSE.

I've noticed this behaviour on similar crates so this might be an issue of the windows api.

Thanks

luukvanderduim

luukvanderduim

1

Hi!

Cool crate you've written. Thanks!

The compiler complains (rightfully so I guess) that the the match in linux/inputs.rs:130, in function: pub fn scan_code_to_key(scan_code: u32) -> Option<KeybdKey> has unreachable patterns. This is because 0x47, 0x48, 0x4b, 0x4d and 0x50 are used more than once and match has no way to distinguish between them.

These are numpad keys with double functions, depending on the num-lock state? I am not sure how to fix this.

emhagman

emhagman

4

Hi!

Thanks for making this lib :)

I am running into an issue where if I a bind to, say, AKey, using AKey::bind the input is always intercepted. I saw a similar thread with the opposite problem where the input was not being intercepted so I wasn't sure if that was ever changed to intercept the input by default? I am using Linux w/ X11.

To be clear:

This very simple example will print a has been pressed in the terminal but then my a key no longer works for typing anything because it seems that the program is preventing the default key action.

As a side note, would it be possible to have an API where we could decide whether to intercept the key or not?

elkowar

elkowar

5

idk if this is realistic to implement (especially cross-plattform), but i'd really need the option to actually "intercept" the keypress in a way that the original key doesn't come through (like for example ahk does it). At the moment when i bind to a key, the original keypress still writes letters and such, this should be preventable

bburdette

bburdette

2

Hey! First off, thanks for the awesome lib. Today I made a program to let me use my phone as a mouse - it works! mousepage on crates.io.

Now I'm looking to get scrolling to work, but looks like the relevant functions are unimplemented! MouseWheel.scroll_ver and MouseWheel.scroll_hor.

mathieucaroff

mathieucaroff

1

Current behavior

Currently, when a key is bound multiple times, the last binding operation overrides the previous ones.

Expected behavior

When a key or mouse event is bound multiple times, InputBot dispatches the event to all callback functions, in the order in which they were registered.

Note: this would be a breaking change.

After thinking about it, I found the current API, with KeydbKey:unbind(&self), would make a rather coarse API, requiring to unregister all callbacks at once.

Alternative

Provide a new interface which handles dispatch.

obv-mikhail

obv-mikhail

enhancement
4

Not sure what will be used for the back-end. Probably libinput.

Status Update:

  • The crate now uses Libinput.
  • Key and button bindings should now work on Wayland.
  • Have to port input simulation.
Versions

Find the latest versions by id

Information - Updated Jun 21, 2022

Stars: 137
Forks: 25
Issues: 22

Rust library for Self Organising Maps (SOM)

Add rusticsom as a dependency in Cargo

Rust library for Self Organising Maps (SOM)

Rust library for parsing configuration files

The 'option' can be any string with no whitespace

Rust library for parsing configuration files

Rust library for the Pimoroni Four Letter pHAT

This library aims to port ht16k33 (or rather a fork, as of right now) so credit goes to ht16k33-diet

Rust library for the Pimoroni Four Letter pHAT

Rust library for emulating 32-bit RISC-V

This library can execute instructions against any memory and register file that implements

Rust library for emulating 32-bit RISC-V

Rust library for connecting to the IPFS HTTP API using Hyper/Actix

You can use actix-web as a backend instead of hyper

Rust library for connecting to the IPFS HTTP API using Hyper/Actix

Rust library to manipulate file system access control lists (ACL) on macOS, Linux, and FreeBSD

This module provides two high level functions, getfacl and setfacl

Rust library to manipulate file system access control lists (ACL) on macOS, Linux, and FreeBSD

Rust library translation (rust-src/rust-std/stdlib/rustlib translation)

This is the place to translate Having a documentation in your native language is essential if you don't speak English, and still enjoyable even if...

Rust library translation (rust-src/rust-std/stdlib/rustlib translation)

Rust library for using Infrared hardware decoders (For example a Vishay TSOP* decoder),

enabling remote control support for embedded project

Rust library for using Infrared hardware decoders (For example a Vishay TSOP* decoder),

Rust library for interaction with the OriginTrail Decentralized Knowledge Graph

open up an issue on this repository and let us know

Rust library for interaction with the OriginTrail Decentralized Knowledge Graph

Rust library for parsing COLLADA files

Notice: This library is built around files exported from Blender 2

Rust library for parsing COLLADA files

Rust library for low-level abstraction of MIPS32 processors

This project is licensed under the terms of the MIT license

Rust library for low-level abstraction of MIPS32 processors
Facebook Instagram Twitter GitHub Dribbble
Privacy