diff options
| author | FenrirWolf <[email protected]> | 2018-04-30 00:39:13 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-04-30 00:39:13 -0600 |
| commit | 71d0a86fbe5f547f3472ea95884472f068423186 (patch) | |
| tree | 6219f9aa2d5fe9e069e07ac9a6c4636f66476f97 /examples/src/bin/software-keyboard.rs | |
| parent | Make travis work again (diff) | |
| parent | Add nul-terminatator to input that expects it (diff) | |
| download | archived-ctru-rs-71d0a86fbe5f547f3472ea95884472f068423186.tar.xz archived-ctru-rs-71d0a86fbe5f547f3472ea95884472f068423186.zip | |
Merge pull request #66 from FenrirWolf/swkbd
Initial software keyboard support
Diffstat (limited to 'examples/src/bin/software-keyboard.rs')
| -rw-r--r-- | examples/src/bin/software-keyboard.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/src/bin/software-keyboard.rs b/examples/src/bin/software-keyboard.rs new file mode 100644 index 0000000..cb1b058 --- /dev/null +++ b/examples/src/bin/software-keyboard.rs @@ -0,0 +1,47 @@ +extern crate ctru; + +use ctru::gfx::Gfx; +use ctru::console::Console; +use ctru::services::apt::Apt; +use ctru::services::hid::{Hid, KeyPad}; +use ctru::applets::swkbd::{Swkbd, Button}; + +fn main() { + let apt = Apt::init().unwrap(); + let hid = Hid::init().unwrap(); + let gfx = Gfx::default(); + let _console = Console::default(); + + println!("Press A to enter some text or press Start to quit"); + + while apt.main_loop() { + gfx.flush_buffers(); + gfx.swap_buffers(); + gfx.wait_for_vblank(); + + hid.scan_input(); + + if hid.keys_down().contains(KeyPad::KEY_A) { + // Prepares a software keyboard with two buttons: One to cancel input and one + // to accept it. You can also use `Swkbd::init()` to launch the keyboard in different + // configurations. + let mut keyboard = Swkbd::default(); + + // String used to store text received from the keyboard + let mut text = String::new(); + + // Raise the software keyboard. You can perform different actions depending on which + // software button the user pressed + match keyboard.get_utf8(&mut text) { + Ok(Button::Right) => println!("You entered: {}", text), + Ok(Button::Left) => println!("Cancelled"), + Ok(Button::Middle) => println!("How did you even press this?"), + Err(_) => println!("Oh noes, an error happened!"), + } + } + + if hid.keys_down().contains(KeyPad::KEY_START) { + break; + } + } +} |