A library for simulating mouse and keyboard events

Overview

The Fat Controller

Crates.io Docs.rs License

TFC is a library for simulating mouse and keyboard events. This library was built for use by TFC-server, a server that allows for remote control of a PC via a mobile app.

Features

  • Mouse clicks
  • Mouse motion (relative and absolute)
  • Mouse scrolling (smooth scrolling where supported)
  • Key presses
  • Translating Unicode characters to key presses
  • Typing arbitrary Unicode strings
  • Getting the mouse position
  • Getting the size of the screen

Platforms

  • Linux - With X11
  • Linux - Without X11
  • macOS
  • Windows

Usage

Add the following to your Cargo.toml:

[dependencies]
tfc = "0.5"

Linux

There are two implementations for Linux, one that uses X11, and one that depends only on the Linux kernel. The implementation that doesn't use X11 is missing some features. It is intended for Wayland but Wayland is a bit more locked down compared to X11, hence the missing features.

With X11

Before using the X11 implementation, the X11, XTest and xkbcommon development libraries need to be installed. Using apt, the following snippet can be used.

sudo apt install libx11-dev libxtst-dev libxkbcommon-dev

Without X11

The non-X11 implementation (called Wayland within the code base) uses /dev/uinput. Before this can be used, TFC needs permission to write to the device. To grant permissions temporarily (until the next reboot), use the following snippet.

chmod +0666 /dev/uinput

To grant permissions permanently, use the following snippet.

# Create a group
sudo groupadd -r uinput
# Add yourself to the group
sudo usermod -aG uinput $USER
# Give the group permissions to use the uinput kernel module
echo 'KERNEL=="uinput", MODE="0660", GROUP="uinput", OPTIONS+="static_node=uinput"' \
| sudo tee /etc/udev/rules.d/60-tfc.rules

Use the following snippet if this doesn't take effect immediately. If all else fails, reboot.

udevadm control --reload-rules && udevadm trigger

To revoke permissions, use the following snippet.

sudo rm /etc/udev/rules.d/60-tfc.rules

Example

use tfc::{Context, Error, traits::*};
use std::{f64::consts::PI, thread, time::Duration};

fn main() -> Result<(), Error> {
    let mut ctx = Context::new()?;
    let radius = 100.0;
    let center = ctx.cursor_location()?;
    let center = (center.0 as f64 - radius, center.1 as f64);
    let steps = 200;
    let revolutions = 3;
    let delay = Duration::from_millis(10);

    for step in 0..steps * revolutions {
        thread::sleep(delay);
        let angle = step as f64 * 2.0 * PI / steps as f64;
        let x = (center.0 + radius * angle.cos()).round() as i32;
        let y = (center.1 + radius * angle.sin()).round() as i32;
        ctx.mouse_move_abs(x, y)?;
    }

    Ok(())
}
Comments
  • Cannot press a key on Linux Wayland

    Cannot press a key on Linux Wayland

    I'm trying to simply press a key with a minimal example :

    use std::thread::sleep;
    use std::time::Duration;
    use tfc::{traits::KeyboardContext, Context, Key};
    
    fn main() {
        println!("Hello, world!");
        let mut ctx = Context::new().unwrap();
        loop {
            sleep(Duration::from_secs(1));
            ctx.key_click(Key::A).unwrap();
            println!("A pressed");
        }
    }
    

    It runs without any error but the A key isn't pressed in practice when I open a text editor for example. I did the chmod +0666 /dev/uinput command but it still seems to do nothing. Any idea of what could be wrong ?

    opened by ValouBambou 7
  • unicode_string collapses repeated characters

    unicode_string collapses repeated characters

    Using 0.5.1 on Windows 10, the following code types abc:

    use tfc::{traits::*, Context, Error};
    
    fn main() -> Result<(), Error> {
        let mut ctx = Context::new()?;
        ctx.unicode_string("aabcccc")?;
        Ok(())
    }
    

    ascii_string works as expected.

    opened by branpk 3
  • Bad security of `/dev/uinput`

    Bad security of `/dev/uinput`

    this line of the readme sudo sh -c 'echo -e "KERNEL==\"uinput\", MODE=\"0666\"" >> /etc/udev/rules.d/50-uinput.rules' Lets any userspace program simulate user input persistent across reboots, which is not enabled by default for Linux for a reason - it is a security issue. This should be clarified in the readme (in addition to how to remove this for Linux newbies).

    The proper way to deal with this for production software is to create a separate group (see weylus' readme)

    The proper way to deal with it for one off local development is probably chmod, as it is not persistent across reboots

    opened by maxbla 3
  • Add examples provided in README to examples/ folder

    Add examples provided in README to examples/ folder

    This makes it runnable like so: cargo run --example rotate-mouse

    Interestingly enough it even works on MacOS out of the box despite a popup coming up to ask for permissions.

    opened by Byron 1
  • I can't figure out how to send 2 keys at once (shift+home)

    I can't figure out how to send 2 keys at once (shift+home)

    When I do:

    ctx.key_down(tfc::Key::Shift)?;
    ctx.key_click(tfc::Key::Home)?;
    ctx.key_up(tfc::Key::Shift)?;
    

    It seems I only get the "home" key:

    https://user-images.githubusercontent.com/24027/188269238-a9faf951-92f2-409f-8fef-0d37ed64e996.mp4

    opened by bbigras 1
  • Incorrect key pressed when using unicode_char_down

    Incorrect key pressed when using unicode_char_down

    When running the following code...

    let mut ctx = Context::new().unwrap();
    ctx.unicode_char_down('s').unwrap();
    ctx.unicode_char_up('s').unwrap();
    

    On my computer it presses the ; key, even though it's supposed to press the s key.

    However the following code works fine:

    let mut ctx = Context::new().unwrap();
    ctx.ascii_char_down(b's').unwrap();
    ctx.ascii_char_up(b's').unwrap();
    

    I'm using Linux (X11).

    opened by Pauan 5
Releases(v0.5.2)
Owner
Indiana Kernick
Indiana Kernick
Completely OBSOLETE Rust HTTP library (server and client)

OBSOLETION NOTICE This library is DEAD. It was a useful experiment and is now being replaced under the scope of the Teepee (experimentation grounds at

Chris Morgan 390 Dec 1, 2022
An HTTP library for Rust

hyper A fast and correct HTTP implementation for Rust. HTTP/1 and HTTP/2 Asynchronous design Leading in performance Tested and correct Extensive produ

null 11k Jan 7, 2023
GraphQL server library for Rust

GraphQL server library for Rust GraphQL is a data query language developed by Facebook intended to serve mobile and web application frontends. Juniper

GraphQL Rust 4.9k Jan 5, 2023
Low level HTTP server library in Rust

tiny-http Documentation Tiny but strong HTTP server in Rust. Its main objectives are to be 100% compliant with the HTTP standard and to provide an eas

null 785 Dec 29, 2022
Opinionated Rust authentication library.

Goals Prevent user enumeration. All routes should be protected against user enumeration, for now we should at least protect against basic enumeration

Paul Makles 28 Nov 21, 2022
Actix-web wrapper for garde, a Rust validation library.

Garde-actix-web   Actix-web wrapper for garde, a Rust validation library. Installation Usage example Feature flags About us Installation [dependencies

Netwo 5 Sep 8, 2023
A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. :zap::crab:

binserve ⚡ ?? A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. ?? UPDATE: N

Mufeed VH 722 Dec 27, 2022
Host These Things Please - a basic http server for hosting a folder fast and simply

http Host These Things Please - a basic HTTP server for hosting a folder fast and simply Selected features See the manpage for full list. Symlinks fol

thecoshman 367 Dec 23, 2022
Simple and fast web server

see Overview Simple and fast web server as a single executable with no extra dependencies required. Features Built with Tokio and Hyper TLS encryption

null 174 Dec 9, 2022
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix Web Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust Features Supports HTTP/1.x and HTTP/2 Streaming and pipelining

Actix 16.3k Jan 8, 2023
A flexible web framework that promotes stability, safety, security and speed.

A flexible web framework that promotes stability, safety, security and speed. Features Stability focused. All releases target stable Rust. This will n

Gotham 2.1k Jan 3, 2023
Sincere is a micro web framework for Rust(stable) based on hyper and multithreading

The project is no longer maintained! Sincere Sincere is a micro web framework for Rust(stable) based on hyper and multithreading. Style like koa. The

null 94 Oct 26, 2022
A starter template for actix-web projects that feels very Django-esque. Avoid the boring stuff and move faster.

Jelly A.K.A, the actix-web starter you probably wish you had. This is provided as-is, and anyone is free to extend it or rework it as they desire - ju

SecretKeys 198 Dec 15, 2022
Add Facebook and Google authentication to your HTTP REST API in Actix-web

I created this project while learning Rust. Project shows how to handle Facebook and Google token verification in Rust using Actix-Web. Hope this help

null 37 Dec 31, 2022
OxHTTP is a very simple synchronous HTTP client and server

OxHTTP is a very simple synchronous implementation of HTTP 1.1 in Rust. It provides both a client and a server.

Oxigraph 13 Nov 29, 2022
A demo blog post engine in Rust, using Rocket and MongoDB

A demo blog post engine written in Rust, using Rocket and MongoDB Quick Start Setup a new MongoDB cluster https://cloud.mongodb.com/ create a new data

Nabil Hachicha 5 Oct 19, 2022
Tiny-lsm - super simple in-memory blocking LSM for constant-size keys and values

tiny-lsm Super simple in-memory blocking LSM for constant-size keys and values. Despite being single-threaded and blocking, this is still capable of o

Tyler Neely 50 Oct 15, 2022
Actix-extras - A collection of additional crates supporting the actix and actix-web frameworks.

actix-extras A collection of additional crates supporting the actix-web and actix frameworks. Crates by @actix Crate actix-cors Cross-origin resource

Actix 506 Dec 27, 2022
The RCOS website and Discord bot.

Telescope - https://rcos.io Telescope is the RCOS website. User Notes If you find issues with Telescope or have a feature you want added, please make

Rensselaer Center for Open Source 18 Dec 21, 2022