keyboard 0.1.0

A small, well-documented library for reading keyboard input on Windows.
# keyboard.rs

[![Crates.io](https://img.shields.io/crates/v/keyboard)](https://crates.io/crates/keyboard)
[![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue)](https://github.com/enesx32/keyboard)
[![Platform](https://img.shields.io/badge/platform-Windows-0078D6)](https://github.com/enesx32/keyboard)

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:

```bash
cargo add keyboard
```

Or add it manually to your `Cargo.toml`:

```toml
[dependencies]
keyboard = "0.1.0"
```

Replace `0.1.0` with the latest published version.

### From GitHub

You can also install the library directly from GitHub:

```bash
cargo add --git https://github.com/enesx32/keyboard keyboard
```

Or add it manually to your `Cargo.toml`:

```toml
[dependencies]
keyboard = { git = "https://github.com/enesx32/keyboard" }
```

## The whole API

```rust
use keyboard::{Key, pressed_keys, read_char, wait_for_key};

// Is a key held down right now?
if Key::Space.is_pressed() {
    println!("jumping!");
}

// What keys are held down right now?
for key in pressed_keys() {
    println!("{key:?} is down");
}

// What character am I typing? ('\0' if nothing printable)
// Shift and Caps Lock are applied for you.
let c = read_char();

if c != '\0' {
    print!("{c}");
}

// Wait for the user to press any key.
let key = wait_for_key();
println!("You pressed {key}");
```

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:

```bash
git clone https://github.com/enesx32/keyboard.git
cd keyboard
```

Run the example:

```bash
cargo run --example readout
```

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.