Function install_hook

Source
pub fn install_hook() -> EventReceiver
Expand description

Installs a hook and returns a receiver to receive the generated event.

§Panics

Panics if other hooks are already installed.

§Example

let rx = hookmap_core::install_hook();
Examples found in repository?
examples/readme_core.rs (line 4)
3fn main() {
4    let rx = hookmap_core::install_hook();
5
6    while let Ok((event, native_handler)) = rx.recv() {
7        match event {
8            Event::Button(event) => {
9                native_handler.dispatch();
10
11                match event.target {
12                    Button::RightArrow => println!("Left"),
13                    Button::UpArrow => println!("Up"),
14                    Button::LeftArrow => println!("Right"),
15                    Button::DownArrow => println!("Down"),
16                    _ => {}
17                };
18            }
19
20            Event::Cursor(e) => {
21                native_handler.block();
22
23                // Reverses mouse cursor movement
24                let (dx, dy) = e.delta;
25                mouse::move_relative(-dx, -dy);
26            }
27
28            Event::Wheel(e) => {
29                native_handler.dispatch();
30                println!("delta: {}", e.delta);
31            }
32        }
33    }
34}