docs.rs failed to build keyboard-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
keyboard.rs
The simplest possible way to read the keyboard on Windows.
No windows, no focus, no message loops - just three functions and one enum.
Installation
From crates.io
Add keyboard to your project using Cargo:
Or add it manually to your Cargo.toml:
[]
= "0.1.0"
Replace 0.1.0 with the latest published version.
From GitHub
You can also install the library directly from GitHub:
Or add it manually to your Cargo.toml:
[]
= { = "https://github.com/enesx32/keyboard" }
The whole API
use ;
// Is a key held down right now?
if Space.is_pressed
// What keys are held down right now?
for key in pressed_keys
// What character am I typing? ('\0' if nothing printable)
// Shift and Caps Lock are applied for you.
let c = read_char;
if c != '\0'
// Wait for the user to press any key.
let key = wait_for_key;
println!;
That's it!
| You want... | Use... |
|---|---|
| Is one key down? | Key::Space.is_pressed() |
| All keys down right now? | pressed_keys() |
| The character being typed? | read_char() |
| Wait for the user to press a key? | wait_for_key() |
| Turn a key into text? | Key::G.to_char() |
Platform support
Only Windows is implemented (keyboard::windows).
Other platforms get a clear compile error instead of silently doing nothing.
Running the example
Clone the repository:
Run the example:
Hold down a few keys and watch the console.
Layout note
Key::to_char() and read_char() map to a standard US (ANSI) keyboard layout.
License
Licensed under either of the following, at your option:
- MIT License
- Apache License, Version 2.0
See LICENSE-MIT and LICENSE-APACHE for details.