A npm package that lets you automate your windows desktop.

Overview

js-macro

A npm package that lets you automate your windows desktop.

npm i js-macro

Examples

  • Simple cursor usage
const { cursor } = require("js-macro");

cursor.position();
// { x: 679, y: 0 }

cursor.move(0, 0);
// cursor is now at the very left top of the screen

cursor.leftClick();
  • Typing something on notepad
const { Worker, isMainThread } = require("worker_threads");
const { execSync } = require("child_process");
const { window } = require("js-macro");

if (!isMainThread) {
    execSync("notepad.exe");
} else {
    // we don't want for execSync to wait for notepad to exit,
    // so we should use a worker instead
    void new Worker(__filename);
    
    // wait for notepad to start
    setTimeout(() => {
        const notepad = window.find("Untitled - Notepad");
        
        if (!notepad) {
            return console.error("error: cannot find notepad :(");
        }
        
        const textBox = notepad.getChild().find(x => x.getClassName() === "Edit");
        
        if (!textBox) {
            return console.error("error: cannot find text box :(");
        }
        
        textBox.type("Hello, World!");
    }, 1000);
}
  • Screenshotting a window, or your desktop (like print-screen!)

The buffers will all be in a PNG format.

const { window } = require("js-macro");
const desktop = window.desktop();

desktop.screenshot(0, 0, "file.png").then(() => console.log("screenshotted!"));
desktop.screenshot(0, 0, 500, 500).then(buf => /* ... */);

Building

To build the library and it's dependencies, you need:

  • Visual C++ Build Environment
  • Powershell v5.0+

To install the dependencies, open powershell and do the following:

cd deps
.\install.ps1

To build the library, go to the root directory and do the following:

npm i -g node-gyp
node-gyp rebuild
Issues
  • Multiple issues | Cannot install, wont compile & requires node >= v18

    Multiple issues | Cannot install, wont compile & requires node >= v18

    Hi there,

    I've wanted to try this project, because it looked promising, but I ran into some issues.

    1. Unable to npm install js-marco

    The NPM package still contains the install script. Which results in NPM executing this after downloading. But since the NPM package doesn't contain the sources it will fail.

    npm install js-macro --ignore-scripts will work

    2. The .node files in the NPM package are tied to NodeJS 18

    The .node files seem to be compiled using NodeJS v18. This results in other node versions trowing the error Module did not self-register...

    3. Trying to build from source fails with NodeJS 16 (current LTS version)

    When trying to build from source I get errors like: node_modules\js-macro\lib\main.cpp(9): error C2280: 'v8::HandleScope::HandleScope(const v8::HandleScope &)': attempting to reference a deleted function

    4. Trying to build from source fails with NodeJS 18

    When building with node 18 it fails with: node_modules\js-macro\bin\zlib1.lib : fatal error LNK1127: library is corrupt


    Unfortunately I'm not very familiar with native libraries and if it's even possible to get this to work on older version of node? Let me know if there's something I can do.

    bug 
    opened by RoelVB 5
  • feat: Added Window.fromPid() method

    feat: Added Window.fromPid() method

    It's me again. I've added a Window.fromPid() method, which makes it a easier/more reliable to find your window, for example:

    const { spawn } = require('node:child_process');
    const { Window, keyboard } = require('js-macro');
    
    const process = spawn('notepad.exe');
    
    setTimeout(async () => {
      let notepad = await Window.fromPid(process.pid);
    
      if (!notepad) {
        return console.error('error: cannot find notepad :(');
      }
    
      notepad.focus();
    
      keyboard.type('Hello, World!');
    }, 1000);
    

    Important note! This is the first time ever I wrote some Rust code. It probably could have been better, but I couldn't find a way to accept a string and u32 at the same time for the constructor.

    opened by RoelVB 1
Releases(v2.0.1)
Owner
"null"
Former Node.js/Python developer, Currently does C/C++ development.
A Flutter package that makes it easy to customize and work with your Flutter desktop app's system tray.

system_tray A Flutter package that that enables support for system tray menu for desktop flutter apps. on Windows, macOS and Linux. Features: - Modify

AnTler 108 Jul 29, 2022
A utility to automate the installation, maintenance, and debugging of Asterisk/DAHDI, while integrating additional patches to provide the richest telephony experience

PhreakScript A utility to automate the installation, maintenance, and debugging of Asterisk/DAHDI, while integrating additional patches to provide the

null 6 Jul 19, 2022
Implémentation en C d'un automate LR1 reconnaissant divers langages

Dans un shell Unix : -WSL (cd /mnt/c pour accéder au répertoire C:) ou Virtualbox linux (dossiers partagés) sous Windows -terminal pour Linux ou MacOs

Aurélien Mazaheri 0 Jun 13, 2022
Björn Kalkbrenner 32 Jul 25, 2022
A Geometry Dash mod that lets you select the screen to run the game on

Screen Selector A mod that lets you select the screen to run Geometry Dash on Fully compatible with Mega Hack v6 (except the "Fullscreen" and "Borderl

ConfiG 8 Jun 3, 2022
Had a tough time playing Microsoft Wordament ? Well WORDament_Solver has your back. It suggests you meaningful words you can use while playing the game and help you top the leaderboard.

WORDament_Solver Had a tough time playing Microsoft Wordament ? Well WORDament_Solver has your back. It suggests you meaningful words you can use whil

Tushar Agarwal 3 Aug 19, 2021
Add virtual monitors to your windows 10 device! Works with Oculus software, obs, and any desktop sharing software

License MIT and CC0 or Public Domain, whichever is least restrictive -- Use it AS IS - NO IMPLICIT OR EXPLICIT warranty This may break your computer,

Rashi Abramson 176 Aug 4, 2022
Lets be creative this hacktober fest. Get started with contributing to open source.

Be Creative this Hacktoberfest 2021 Lets be creative this hacktober fest. Get started with contributing to open source. ?? Web-Ideas ?? How Can I Cont

B L A C K F U R Y 10 Nov 20, 2021
Lock you keyboard and clean your screen. A simple, and easy way to clean your computers.

Pristine Cleaner A screen and keyboard cleaning application made to turn screen black, and lock keyboard for easy cleaning. With features such as star

Rhino Inani 2 Jan 16, 2022
Flutter app where you can find your information about your Favorite Super Cars ⚡❤

Super Cars App (Flutter) ⚡ Now you can freely discover and browse your Favourite Super Cars ❤ . Speed! ?? Getting Started This project is a starting p

Shehroz Ali 4 Apr 13, 2022
A program that allows you to hide certain windows when sharing your full screen

Invisiwind Invisiwind (short for Invisible Window) is an application that allows you to hide certain windows when sharing your full screen.

Joshua T. 59 Jul 16, 2022
A beginner friendly desktop UI for Tasmota flashed devices for Windows, macOS and Linux.

TasmoManager A beginner friendly desktop UI for Tasmota flashed devices for Windows, macOS and Linux. Features Native Tasmota device discovery (via ta

Tom Butcher 46 Jul 16, 2022
Windscribe 2.0 desktop client for Windows, Mac and Linux

Windscribe 2.0 Desktop Application This repo contains the complete source code for the Windscribe 2.0 app. This includes installer, service/helper, ba

Windscribe 293 Jul 29, 2022
Dwm_lut - Apply 3D LUTs to the Windows desktop for system-wide color correction/calibration

About This tool applies 3D LUTs to the Windows desktop by hooking into DWM. It works in both SDR and HDR modes, and uses tetrahedral interpolation on

null 145 Jul 28, 2022
A desktop (supports macOS and Windows) implementation of uni_links plugin.

uni_links_desktop A desktop (supports macOS and Windows) implementation of uni_links plugin. uni_links_desktop Platform Support Quick Start Installati

LeanFlutter 13 Jul 12, 2022
Defender-control - An open-source windows defender manager. Now you can disable windows defender permanently.

Defender Control Open source windows defender disabler. Now you can disable windows defender permanently! Tested from Windows 10 20H2. Also working on

null 363 Jul 31, 2022
this package help you to give glassomorphic+ neomrphic both effects to a container (at a time).

duomorphsim this package help you to give glassomorphic+ neomrphic both effects to a container (at a time). Usage DuoMorphicCard need four argument wh

Lokesh Jangid 3 Aug 23, 2021
NightDriverStrip is a source code package for building a flash program that you upload to the ESP32 microcontroller.

NightDriverStrip is a source code package for building a flash program that you upload to the ESP32 microcontroller.

Plummer's Software LLC 563 Jul 1, 2022
A python package to provide you with many useful tools for osu! servers, written in C++ for the best speeds possible.

pysu_bindings A python package to provide you with many useful tools for osu! servers, written in C++ for the best speeds possible. What? As most peop

James 2 Nov 29, 2021