Crates.io | razerctl |
lib.rs | razerctl |
version | 0.3.4 |
created_at | 2024-12-18 19:09:48.973102+00 |
updated_at | 2025-06-15 14:04:55.46196+00 |
description | Allows you to control your mouse and keyboard with Razer Synapse |
homepage | https://docs.rs/crate/razerctl/latest |
repository | https://github.com/BlankyWacky/razerctl |
max_upload_size | |
id | 1488360 |
size | 34,112 |
A low-level Rust library for controlling Razer mouse and keyboard input directly through the Razer Synapse driver on Windows.
unsafe
Windows API and driver interactions.This library works by locating the symbolic link to the RZCONTROL
device created by the Razer Synapse driver and communicating with it directly using DeviceIoControl
.
Keyboard input is not sent using standard Windows scan codes. Instead, this crate implements a custom translation layer that converts standard Virtual-Key (VK) codes into the specific MakeCode
values the Razer driver expects. This logic was ported from the IbInputSimulator C++ project.
1. Add razerctl
to your project:
cargo add razerctl
2. (Recommended) Add win_key_codes
for easy keyboard control:
For sending keyboard input, you need to provide Windows Virtual-Key codes. The win_key_codes
crate provides convenient constants for these codes.
cargo add win_key_codes
Here is a quick example of how to initialize the library, move the mouse, and press the 'A' key.
use std::{io::Error, thread, time::Duration};
use razerctl::{init, mouse_move, key_down, key_up};
use win_key_codes::VK_A; // Use a constant for the 'A' key
fn main() -> Result<(), Error> {
// 1. Initialize the connection to the Razer driver
init()?;
println!("Razer driver initialized.");
// 2. Move the mouse relatively by (100, 100) pixels
println!("Moving mouse...");
mouse_move(100, 100)?;
// Give a moment for the mouse move to be visible
thread::sleep(Duration::from_secs(1));
// 3. Simulate pressing and releasing the 'A' key
println!("Pressing the 'A' key...");
key_down(VK_A)?;
thread::sleep(Duration::from_millis(50)); // Hold the key for 50ms
key_up(VK_A)?;
println!("Done!");
Ok(())
}
This crate uses unsafe
code to interface with the Windows API and the device driver. However, the public API is designed to be a completely safe abstraction over these details. All unsafe
blocks are contained internally and have been written with care.
You can run the included examples from the project root:
# --- Mouse Examples ---
cargo run --example left_click
cargo run --example mouse_move1
cargo run --example mouse_move2
# --- Keyboard Example ---
cargo run --example keyboard_test
Contributions are welcome! If you find a bug or have an idea for an improvement, please feel free to submit an issue or a pull request.
This project is licensed under the MIT License.