MyNixOS website logo
Description

Take Screenshots (Screen Capture) from R Command.

Take screenshots from R command and locate an image position.

screenshot

The goal of screenshot is to take a screenshot easily and locate image position on a display with R.

Installation

You can install the development version from GitHub with:

  # install.packages("remotes")
remotes::install_github("matutosi/screenshot")
install.packages("screenshot")  # You can also install from CRAN:

On Windows, need to install screenshot.exe by install_screenshot(). This exe file is compiled from codes shown below.

https://superuser.com/questions/75614/take-a-screen-shot-from-command-line-in-windows#answer-1751844

library(screenshot)
  # required on win
install_screenshot()
  # if you want to install another directory
  # bin_dir <- "SET_YOUR DIRECTORY"
  # install_screenshot(bin_dir)

On Mac screencapture is usually available.

On Linux GNOME desktop use gnome-screenshot. If not installed, run sudo apt install gnome-screenshot.

Example

You can use screenshot() to take a screenshot easily.

library(screenshot)
sc <- screenshot()
sc_image <- imager::load.image(sc)
plot(sc_image)

To locate image from a screenshot, use locate_image(). In this case, bottom left corner of screenshot image was cut off as needle image.

sc <- screenshot()
sc_image <- imager::load.image(sc)
w <- 100
h <- 80
pos_x <- 1
pos_y <- imager::height(sc_image) - h
needle <- hay2needle(sc_image, pos_x, pos_y, w, h)
(locate_image(needle)) # center location
pos <- locate_image(needle, center = FALSE)
found <- hay2needle(sc_image, pos[1], pos[2], w, h)
layout(c(1:3))
plot(sc_image)
plot(needle)
plot(found)

On Windows, clipboad image can be saved by save_clipboard_image().

path_img <- "path_of_png_file"
save_clipboard_image(path_img)
shell.exec(path_img)

Caution (=0.9.0)

  • Automatically adjusted in 0.9.1 and latter.

When changing display DPI scaling, need to adjust position.

  # when using 125%
pos <- locate_image(IMAGE_TO_CLICK) / 1.25
KeyboardSimulator::mouse.move(pos[1], pos[2])
KeyboardSimulator::mouse.click()

You can see display scale in setting app as shown below.

Citation

Toshikazu Matsumura (2023) screenshot. Screenshot and locate image Easily. https://github.com/matutosi/screenshot/.

Metadata

Version

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