MyNixOS website logo
Description

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 '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.

keypress

Read a single key press from the terminal

R-CMD-check CRAN RStudio mirrordownloads Codecov testcoverage

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 OSX 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, OSX, 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 OS X keyboards: home, end, insert, delete, pageup, pagedown.
  • On Linux and OS X Unicode characters are supported, but not (yet) on Windows. Unicode characters are returned UTF-8 encoded.

License

MIT © Gábor Csárdi.

Metadata

Version

1.3.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows