Wait for a single key press at the 'R' prompt. This works in terminals, but does not currently work in the 'Windows' 'GUI', the 'OS X' 'GUI' ('R.app'), in 'Emacs' 'ESS', in an 'Emacs' shell buffer or in 'R Studio'. In these cases 'keypress' stops with an error message.
devtools::install_github("gaborcsardi/keypress")> has_keypress_support()[1] TRUE> x <- keypress()> cat("You pressed key", x, "\n")You pressed key hThis is unfortunately impossible to do in
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, OSX, or other Unix terminal or Windows cmd (also called RTerm in R).
Note that not all keys are supported, in particular the modifiers (ctrl, alt, etc.) are not. Supported special keys are:
up, down, right, left. Available on most keyboards.f1 to f12. Available on most keyboards.home, end, insert, delete, pageup, pagedown. Note
that these are not available on OSX keyboards, so it is not a good
idea to use them.MIT © Gábor Csárdi
First released version.