Welcome to
LepikJS

A versatile NodeJS library for managing a wide range of events including mouse and keyboard interactions, screen actions like print screen, as well as various Windows events

Documentation

First words

LepikJS is a Node.js package designed for managing an array of events, encompassing mouse and keyboard interactions, screen actions like print screen, and a spectrum of Windows events including application openings and closures.

One of the standout advantages of this library is its dual capability: not only can it actively listen to events, but it can also emit them. This unique trait empowers the creation of straightforward event-driven applications.

Installation

To install the library, you can use npm or yarn.

LepikJS has 10 000+ downloads via NPM.

npm:

  npm install lepikjs

yarn:
yarn add lepikjs
Nothin' else.

Enviroment (Windows users can skip)

If you are on windows, no extra installations. You are ready to go!

If you are on Linux, Mac, etc... You need to have Python 3.6 or higher installed for the event listening.
You can install it here Python.org

Having NodeJS ^16.x (or higher) installed is also required.

Usage

To use the library, you need to import it.

const lepik = require("lepikjs")

Then you can use it.

Listening Events

LepikJS has many events.
To listen to them, you can use the on method.

Listening to mouse click:

lepik.on("mouseClick", (event) => {
  console.log("Position x: " + event.x );
  console.log("Position y: " + event.y); 
  console.log("Button: " + event.button); 
})
The event.x & event.y parameter are x and y position of the mouse click.
The event.button parameter is a number that represents the button that was clicked.
The number is 0 for left, 1 for right and 2 for middle.

Listening to mouse move:

lepik.on("mouseMove", (event) => {
            console.log("Position x: " + event.x );
            console.log("Position y: " + event.y); 
            console.log("Timestamp: " + event.time); 
            })
          

Listening to mouse down:

lepik.on("mouseDown", (event) => {
            console.log("Position x: " + event.x );
            console.log("Position y: " + event.y); 
            })
          
The event.x & event.y parameter are x and y position of the mouse down.

Listening to mouse up:

lepik.on("mouseUp", (event) => {
            console.log("Position x: " + event.x );
            console.log("Position y: " + event.y); 
            })
          
The event.x & event.y parameter are x and y position of the mouse up.

Listening to mouse Double Click:

lepik.on("mouseDoubleClick", (event) => {
            console.log("Position x: " + event.x );
            console.log("Position y: " + event.y); 
            console.log("Button: " + event.button); 
            })
          
The event.x & event.y parameter are x and y position of the mouseDoubleClick.
The event.button parameter is a number that represents the button that was clicked.
The number is 0 for left, 1 for right and 2 for middle.

Listening to key press:

 lepik.on("keyPress", (key) => {
  console.log(key + " pressed")
})
The key parameter is the key that was pressed.

Listening to key up:

lepik.on("keyUp", (key) => {
  console.log(key + " released")
})
The key parameter is the key that was released.

Listening to key down:

lepik.on("keyDown", (key) => {
  console.log(key + " released")
})
The key parameter is the key that was pushed.

Getting Events

Get current mouse position:

let pos = await lepik.getMousePosition()
            console.log("Position x: " + pos.x );
            console.log("Position y: " + pos.y);
Returns the current mouse position as object with x and y attributes.

Get current screen size:

let size = await lepik.getScreenSize()
            console.log("Position x: " + size.width );
            console.log("Position y: " + size.height );
Returns the current screen site as object with width and height attributes.

Get get Active Window:

let window = await lepik.getActiveWindow()
            console.log("Current window: " + window);
Returns the current window handle (or id on unix systems).

Get window title:

let windowTitle = await lepik.getWindowTitle(window)
            console.log("Window Title: " + windowTitle );
Returns the window title string.

Get window size:

let win = await lepik.getWindowSize(window)
            console.log("Window width: " + win.width );
            console.log("Window height: " + win.height );
Returns the window title string.

Emitting Events

Emiting mouse click:

lepik.mouseClick(key,amount)
The key parameter can be 0 for left, 1 for right and 2 for middle. Strings "left", "right" and "middle" are also accepted. The amount parameter is the amount of clicks. (default: 1)

Emiting mouse double-click:

lepik.mouseDoubleClick(key)
Same rules as above, but the amount parameter cannot be changed. (default: 2)

Emiting mouse mouseMove:

lepik.mouseMove(x, y, absolute, duration)
The x and y parameters are the new position of the mouse.
The absolute parameter is a boolean that determines if the movement is absolute or relative.
The duration parameter is the time in milliseconds the mouse should move. Absolute and duration are optional.

Emiting mouse drag:

lepik.mouseDrag(fromX,fromY,toX,toY,absolute,duration)
The fromX and fromY parameters are the starting position of the mouse.
The toX and toY parameters are the ending position of the mouse.
The absolute parameter is a boolean that determines if the movement is absolute or relative.
The duration parameter is the time in milliseconds the mouse should move. Absolute and duration are optional.

Emiting mouse scroll:

lepik.mouseScroll(amount)
The amount parameter is the amount of scroll. (default: 1) Negative values scroll down, positive values scroll up.

Emiting key tap:

lepik.keyTap(key)
The key parameter is the key that will be tapped. If needed to press more keys and once concencate them with + . Ex. "ctrl+alt+delete"

Emiting keyboard write string:

lepik.write(text,duration)
The text parameter is the text that will be written. The duration parameter is the time in milliseconds the text should be written. (default: .1) Duration is optional.