> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/k/keyboard-input/obtain_a_y_or_n_response.md).

# Obtain a Y or N response

```ruby
func prompt_yn {
    static rk = frequire('Term::ReadKey')
    rk.ReadMode(4)     # change to raw input mode
 
    var key = ''
    while (key !~ /[yn]/i) {
        while (rk.ReadKey(-1) != nil) {}   # discard any previous input
        print "Type Y/N: "
        say (key = rk.ReadKey(0))          # read a single character
    }
 
    rk.ReadMode(0)     # reset the terminal to normal mode
    return key.uc
}
 
var key = prompt_yn()
say "You typed: #{key}"
```

#### Output:

```
Type Y/N: a
Type Y/N: b
Type Y/N: c
Type Y/N: y
You typed: Y
```
