The goal of screenshot is to take a screenshot easily and locate image position on a display with R.
You can install the development version from GitHub with:
# install.packages("remotes")
::install_github("matutosi/screenshot")
remotesinstall.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
.
You can use screenshot()
to take a screenshot
easily.
library(screenshot)
<- screenshot()
sc <- imager::load.image(sc)
sc_image 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.
<- screenshot()
sc <- imager::load.image(sc)
sc_image <- 100
w <- 80
h <- 1
pos_x <- imager::height(sc_image) - h
pos_y <- hay2needle(sc_image, pos_x, pos_y, w, h)
needle locate_image(needle)) # center location
(<- locate_image(needle, center = FALSE)
pos <- hay2needle(sc_image, pos[1], pos[2], w, h)
found layout(c(1:3))
plot(sc_image)
plot(needle)
plot(found)
On Windows, clipboad image can be saved by
save_clipboard_image()
.
<- "path_of_png_file"
path_img save_clipboard_image(path_img)
shell.exec(path_img)
When changing display DPI scaling, need to adjust position.
# when using 125%
<- locate_image(IMAGE_TO_CLICK) / 1.25
pos ::mouse.move(pos[1], pos[2])
KeyboardSimulator::mouse.click() KeyboardSimulator
You can see display scale in setting app as shown below.
Toshikazu Matsumura (2023) screenshot. Screenshot and locate image Easily. https://github.com/matutosi/screenshot/.