Git Product home page Git Product logo

robot-ts's Introduction

Robot TS 🤖

npm version

This library is inspired by older unmaintained libraries like octalmage/robotjs and Robot/robot-js. The goal is to provide cross-platform controls for various devices such as keyboard, mouse, and screen for Node.js applications.

You can find C++ implementation CMake library 📚 here: developer239/robot-cpp

Supported system:

  • MacOS
  • Windows (not tested yet)

In case of Linux, please, create issue and leave a star ⭐ and I will implement support. Right now I want to focus on port to Node.js using Node-API.

Known issues:

  • Work in progress. If you need specific features, please, create an issue and I will prioritize it.
  • I never tested this on Windows. 🙏
  • It seems that special keys bindings are not implemented correctly.
  • Upper case is converted to lower case when typing. (it will be possible to use shift key when special keys are fixed though)
  • It seems that screen bindings are not implemented correctly.

Installation:

Make sure that you can build C++ projects on your machine and that you have CMake installed.

  • On MacOS: brew install cmake
  • On Windows: choco install cmake

Install Node dependencies:

yarn add robot-ts

Keyboard ⌨️

The Keyboard class provides a interface for simulating keyboard key presses, releases, and typing.

Public Methods

  • type(query: string): void Types the given text as a string.

  • typeHumanLike(query: string): void Types the given text as a string with a human-like typing speed.

  • click(asciiChar: string): void Simulates a key press and release for the specified ASCII character.

  • click(specialKey: SpecialKey): void Simulates a key press and release for the specified special key.

  • press(asciiChar: string): void Simulates a key press for the specified ASCII character.

  • press(specialKey: SpecialKey): void Simulates a key press for the specified special key.

  • release(asciiChar: string): void Simulates a key release for the specified ASCII character.

  • release(specialKey: SpecialKey): void Simulates a key release for the specified special key.

Example Usage

import { Keyboard } from "robot-ts";

Keyboard.typeHumanLike("hello, world");

Mouse 🖱️

The Mouse class provides a interface for controlling the mouse cursor, simulating mouse clicks, and scrolling.

Public Methods

  • move(point: Point): void Moves the mouse cursor to the specified point (x, y).

  • moveSmooth(point: Point, speed?: number): void Moves the mouse cursor smoothly to the specified point (x, y) at the given speed.

  • drag(point: Point, speed?: number): void Drags the mouse cursor to the specified point (x, y) at the given speed.

  • getPosition(): Point Returns the current position of the mouse cursor as a Point.

  • toggleButton(down: boolean, button: MouseButton, doubleClick?: boolean): void Presses or releases the specified mouse button depending on the down argument. If doubleClick is set to true, it will perform a double click.

  • click(button: MouseButton): void Simulates a single click using the specified mouse button.

  • doubleClick(button: MouseButton): void Simulates a double click using the specified mouse button.

  • scrollBy(y: number, x?: number): void Scrolls the mouse wheel by the specified x and y distances.

Example Usage

import { Mouse } from "robot-ts";

Mouse.moveSmooth({ x: 100, y: 200 });

Screen 🖥️

The Screen class provides functionality to capture the screen, get pixel colors, and save the captured screen as a PNG image.

Public Methods

  • getPixelColor(x: number, y: number): Pixel Returns the color of the pixel at the specified (x, y) coordinates as a Pixel structure.

  • getScreenSize(): DisplaySize Returns the size of the screen as a DisplaySize structure containing the width and height.

  • capture(x?: number, y?: number, width?: number, height?: number): void Captures a rectangular area of the screen defined by the specified (x, y) coordinates and dimensions (width, height).

  • getPixels(): Pixel[] Returns an array of Pixel structures representing the captured screen.

  • saveAsPNG(filename: string): void Saves the captured screen as a PNG image with the specified filename.

Example Usage

import { Screen } from "robot-ts";

const screen = new Screen();
screen.capture(0, 0, 800, 600);
const pixel = screen.getPixelColor(100, 200);
screen.saveAsPNG("screenshot.png");

robot-ts's People

Contributors

developer239 avatar semantic-release-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

robot-ts's Issues

fix screen bindings

It seems that even though this class is not static, it is being treated as if it were.

const screen = new Screen();
               ^
TypeError: robot_ts_1.Screen is not a constructor

update CI

  • use latest actions/version and lock them
  • run on ubuntu (MacOS is expensive but more importantly it is not necessary to build native modules to make the release so skip scripts)

use namespaces

KeyboardType -> Keyboard::Type I wrote this because I didn't notice that linker complainer about something else.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.