diff --git a/services/keyboard/Cargo.toml b/services/keyboard/Cargo.toml index 69ea7926a..1b725ed5c 100644 --- a/services/keyboard/Cargo.toml +++ b/services/keyboard/Cargo.toml @@ -29,7 +29,8 @@ hosted = ["utralib/hosted"] renode = ["utralib/renode"] dvt = [] debugprint = [] -debuginject = [] # used only if you want key injection via the UART +debuginject = [] # used only if you want direct key injection via serial or USB. Could be a security risk! rawserial = [] braille = [] -default = ["debuginject"] # "debugprint" +inject-api = [] # used by the serial feature in usb +default = ["debuginject", "inject-api"] # "debugprint" diff --git a/services/keyboard/src/lib.rs b/services/keyboard/src/lib.rs index 3a4f57290..4eadb4590 100644 --- a/services/keyboard/src/lib.rs +++ b/services/keyboard/src/lib.rs @@ -112,6 +112,16 @@ impl Keyboard { c as u32 as usize, 0, 0, 0 )).unwrap(); } + + /// This is used to shove keys into the keyboard module as if you were typing on the + /// physical keyboard. + #[cfg(feature="inject-api")] + pub fn inject_key(&self, c: char) { + send_message(self.conn, + Message::new_scalar(Opcode::InjectKey.to_usize().unwrap(), + c as u32 as usize, 0, 0, 0 + )).unwrap(); + } } use core::sync::atomic::{AtomicU32, Ordering};