This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f77677
commit d166c73
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |