pc_remote/input/
keyboard.rs1use crate::prelude::*;
2use super::Key;
3use enigo::{ Enigo, Direction, Keyboard as EnigoKeyboard, Settings };
4
5#[derive(Debug)]
7pub struct Keyboard {
8 enigo: Enigo,
9}
10
11impl Keyboard {
12 pub fn new() -> Result<Self> {
14 Ok(Self {
15 enigo: Enigo::new( &Settings::default() )?,
16 })
17 }
18
19 pub fn press(&mut self, keys: &[Key]) -> Result<()> {
21 for key in keys {
22 self.enigo.key(key.clone().into(), Direction::Press)?;
23 }
24
25 Ok(())
26 }
27
28 pub fn release(&mut self, keys: &[Key]) -> Result<()> {
30 for key in keys {
31 self.enigo.key(key.clone().into(), Direction::Release)?;
32 }
33
34 Ok(())
35 }
36}