Title: | Wait for a Key Press in a Terminal |
---|---|
Description: | 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. |
Authors: | Gábor Csárdi [aut, cre], Jon Griffiths [aut] |
Maintainer: | Gábor Csárdi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.3.1.9000 |
Built: | 2025-01-09 06:25:50 UTC |
Source: | https://github.com/gaborcsardi/keypress |
Check if the current platform/terminal supports reading single keys.
has_keypress_support()
has_keypress_support()
Supported platforms:
Terminals in Windows and Unix.
RStudio terminal.
Not supported:
RStudio (if not in the RStudio terminal).
R.app on macOS.
Rgui on Windows.
Emacs ESS.
Others.
Whether there is support for waiting for individual keypressses.
Other keypress function:
keypress()
has_keypress_support()
has_keypress_support()
It currently only works at Linux/Unix and OSX terminals,
and at the Windows command line. see has_keypress_support
.
keypress(block = TRUE)
keypress(block = TRUE)
block |
Whether to wait for a key press, if there is none available now. |
The following special keys are supported:
Arrow keys: 'up', 'down', 'right', 'left'.
Function keys: from 'f1' to 'f12'.
Others: 'home', 'end', 'insert', 'delete', 'pageup', 'pagedown', 'tab', 'enter', 'backspace' (same as 'delete' on OSX keyboards), 'escape'.
Control with one of the following keys: 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'k', 'l', 'n', 'p', 't', 'u', 'w'.
The key pressed, a character scalar. For non-blocking reads NA is returned if no keys are available.
Other keypress function:
has_keypress_support()
x <- keypress() cat("You pressed key", x, "\n")
x <- keypress() cat("You pressed key", x, "\n")
For Linux/Unix and OSX terminals, suppress key echoes from the terminal.
without_echo(expr)
without_echo(expr)
expr |
Expression to evaluate without terminal echo. |
You will need to set echo to FALSE if you want the R script to handle all of the keypress-related behaviour, without any keys being echoed in the terminal by the operating system, when using non-blocking keypress. This is not necessary when running in a Windows command prompt, and will be safely ignored.