Wait for a Key Press in a Terminal

Wait for a single key press at the 'R' prompt. This works in terminals, but does not currently work in the 'Windows' 'GUI', the 'macOS' 'GUI' ('R.app'), in 'Emacs' 'ESS', in an 'Emacs' shell buffer or in 'R Studio'. In these cases 'keypress' stops with an error message.


keypress

Read a single key press from the terminal

R-CMD-check CRAN RStudio mirrordownloads Codecov test coverage

Installation

install.packages("keypress")

Usage

> has_keypress_support()
[1] TRUE
> x <- keypress()
> cat("You pressed key", x, "\n")
You pressed key h

Support

This is unfortunately impossible to do in

  • RStudio,
  • R.app (the builtin macOS GUI),
  • RGui (the builtin Windows GUI),
  • Emacs ESS, or
  • if stdin() is not a terminal.

In other words, it pretty much only works interactively, in a terminal. The terminal can be pretty much any Linux, macOS, or other Unix terminal or Windows cmd (also called RTerm in R).

Keys

Note that not all keys are supported, in particular most of the modifiers (alt, shift, etc.) are not. Supported special keys are:

  • Arrow keys: up, down, right, left. Available on most keyboards.
  • Function keys: from f1 to f12. Available on most keyboards.
  • Other special keys: enter, backspace, escape, tab.
  • Some key combinations with the CONTROL key: ctrl-a, ctrl-b, ctrl-c, ctrl-d, ctrl-e, ctrl-f, ctrl-h, ctrl-k, ctrl-l, ctrl-n, ctrl-p, ctrl-t, ctrl-u, ctrl-w.
  • Keys typically not availale on macOS keyboards: home, end, insert, delete, pageup, pagedown.
  • On Linux and macOS Unicode characters are supported, but not (yet) on Windows. Unicode characters are returned UTF-8 encoded.

License

MIT © Gábor Csárdi

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("keypress")

1.3.2 by Gábor Csárdi, 4 months ago


https://github.com/gaborcsardi/keypress#readme


Report a bug at https://github.com/gaborcsardi/keypress/issues


Browse source code at https://github.com/cran/keypress


Authors: Gábor Csárdi [aut, cre, cph] (ORCID: , Jon Griffiths [aut] , Posit Software , PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>)


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests testthat, withr


Imported by climenu, cursr.


See at CRAN