New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bunbot

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bunbot - npm Package Compare versions

Comparing version

to
0.0.2

release/darwin-arm64

42

dist/index.d.ts

@@ -1,9 +0,37 @@

declare type Signal = {
signal: 'CtrlC' | 'CtrlD' | null;
value: string | null;
declare type Coords = {
x: number;
y: number;
};
declare function freeString(ptr: number): void;
declare function getVersion(): string;
declare function getMouseColor(): string;
export { Signal, freeString, getMouseColor, getVersion };
declare class Bunbot {
constructor();
freeString(ptr: number): void;
getRobotGoVersion(): string;
getMousePositionColor(): string;
getScreenSize(): Coords;
getScaleSize(): Coords;
/**
* @param {number} millisecond Default mouse sleep time
*/
setMouseSleep(millisecond: number): void;
scrollMouse(x: number, y: number): void;
moveMouse(x: number, y: number): void;
moveMouseSmooth(x: number, y: number): void;
getMousePosition(): Coords;
/**
* @param {string} button Button to click to
* @param {boolean} doubleClick Should double click
*/
click(button?: 'right' | 'left' | 'wheelLeft', doubleClick?: boolean): void;
/**
* @param {string} text Text to type
*/
type(text: string): void;
/**
* @param {string} key Key
* @param {string} modifiers Modifiers
*/
tap(key: string, ...modifiers: string[]): void;
}
export { Bunbot, Bunbot as default };

@@ -23,7 +23,7 @@ "use strict";

__export(src_exports, {
freeString: () => freeString,
getMouseColor: () => getMouseColor,
getVersion: () => getVersion
Bunbot: () => Bunbot,
default: () => src_default
});
module.exports = __toCommonJS(src_exports);
var import_bun_ffi3 = require("bun:ffi");

@@ -33,3 +33,4 @@ // src/ffi.ts

var import_meta = {};
var { symbols } = (0, import_bun_ffi.dlopen)(`${import_meta.dir}/../release/bunbot.${import_bun_ffi.suffix}`, {
var location = new URL(`../release/${process.platform}-${process.arch}`, import_meta.url).pathname;
var { symbols } = (0, import_bun_ffi.dlopen)(location, {
GetVersion: {

@@ -43,2 +44,42 @@ args: [],

},
GetScreenSize: {
args: [],
returns: import_bun_ffi.FFIType.ptr
},
GetScaleSize: {
args: [],
returns: import_bun_ffi.FFIType.ptr
},
SetMouseSleep: {
args: [import_bun_ffi.FFIType.int],
returns: import_bun_ffi.FFIType.void
},
ScrollMouse: {
args: [import_bun_ffi.FFIType.int, import_bun_ffi.FFIType.int],
returns: import_bun_ffi.FFIType.void
},
Move: {
args: [import_bun_ffi.FFIType.int, import_bun_ffi.FFIType.int],
returns: import_bun_ffi.FFIType.void
},
MoveSmooth: {
args: [import_bun_ffi.FFIType.int, import_bun_ffi.FFIType.int, import_bun_ffi.FFIType.f64, import_bun_ffi.FFIType.f64],
returns: import_bun_ffi.FFIType.bool
},
GetMousePos: {
args: [],
returns: import_bun_ffi.FFIType.ptr
},
Click: {
args: [import_bun_ffi.FFIType.ptr, import_bun_ffi.FFIType.bool],
returns: import_bun_ffi.FFIType.void
},
TypeStr: {
args: [import_bun_ffi.FFIType.ptr],
returns: import_bun_ffi.FFIType.void
},
KeyTap: {
args: [import_bun_ffi.FFIType.ptr, import_bun_ffi.FFIType.ptr],
returns: import_bun_ffi.FFIType.ptr
},
FreeString: {

@@ -49,22 +90,70 @@ args: [import_bun_ffi.FFIType.ptr],

});
function freeString(ptr) {
symbols.FreeString(ptr);
// src/utils.ts
var import_bun_ffi2 = require("bun:ffi");
var utf8e = new TextEncoder();
function encode(data) {
return utf8e.encode(data + "\0");
}
function getVersion() {
const ptr = symbols.GetVersion();
const str = new import_bun_ffi.CString(ptr);
freeString(str.ptr);
function toString(ptr) {
const str = new import_bun_ffi2.CString(ptr);
symbols.FreeString(str.ptr);
return str.toString();
}
function getMouseColor() {
const ptr = symbols.GetMouseColor();
const str = new import_bun_ffi.CString(ptr);
freeString(str.ptr);
return str.toString();
}
// src/index.ts
var Bunbot = class {
constructor() {
}
freeString(ptr) {
symbols.FreeString(ptr);
}
getRobotGoVersion() {
const ptr = symbols.GetVersion();
return toString(ptr);
}
getMousePositionColor() {
const ptr = symbols.GetMouseColor();
return toString(ptr);
}
getScreenSize() {
const ptr = symbols.GetScreenSize();
return JSON.parse(toString(ptr));
}
getScaleSize() {
const ptr = symbols.GetScaleSize();
return JSON.parse(toString(ptr));
}
setMouseSleep(millisecond) {
symbols.SetMouseSleep(millisecond);
}
scrollMouse(x, y) {
symbols.ScrollMouse(x, y);
}
moveMouse(x, y) {
symbols.Move(x, y);
}
moveMouseSmooth(x, y) {
symbols.MoveSmooth(x, y);
}
getMousePosition() {
const ptr = symbols.GetMousePos();
return JSON.parse(toString(ptr));
}
click(button = "left", doubleClick = false) {
symbols.Click((0, import_bun_ffi3.ptr)(encode(button)), Number(doubleClick));
}
type(text) {
symbols.TypeStr((0, import_bun_ffi3.ptr)(encode(text)));
}
tap(key, ...modifiers) {
const keyPtr = (0, import_bun_ffi3.ptr)(encode(key));
const modifiersPtr = (0, import_bun_ffi3.ptr)(encode(modifiers));
symbols.KeyTap(keyPtr, modifiersPtr);
}
};
var src_default = Bunbot;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
freeString,
getMouseColor,
getVersion
Bunbot
});

11

package.json
{
"name": "bunbot",
"version": "0.0.1",
"version": "0.0.2",
"main": "dist/index.js",

@@ -14,3 +14,3 @@ "module": "dist/index.mjs",

},
"description": "",
"description": "Native cross-platform GUI automation for Bun.",
"scripts": {

@@ -28,3 +28,8 @@ "build": "tsup",

"keywords": [
"bun"
"bun",
"robot",
"automation",
"bunjs",
"javascript",
"autopilot"
],

@@ -31,0 +36,0 @@ "license": "MIT",

# bunbot
Native cross-platform GUI automation for the Bun runtime.
[![npm (tag)](https://img.shields.io/npm/v/bunbot?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/bunbot) ![NPM](https://img.shields.io/npm/l/bunbot?style=flat&colorA=000000&colorB=000000)
## Install
Native cross-platform GUI automation for the Bun runtime. Supports Mac and Windows for now.
## Requirements
Bunbot uses [RobotGo](https://github.com/go-vgo/robotgo) via `bun:ffi`. Please see RobotGo's requirements [here](https://github.com/go-vgo/robotgo#requirements).
## Usage
```bash

@@ -11,13 +17,55 @@ bun add bunbot

## Usage
### Mouse
```ts
import { scrollMouse } from 'bunbot'
import Bunbot from 'bunbot'
scrollMouse(10, 'up')
scrollMouse(20, 'right')
const bb = new Bunbot()
// Click
bb.click()
// Get mouse position coordinates
const mousePosition = bb.getMousePosition()
// Move mouse
bb.moveMouse(200, 400)
// Move mouse smoothly
bb.moveMouseSmooth(200, 400)
// Scroll mouse
bb.scrollMouse(100, 200)
```
### Keyboard
```ts
import Bunbot from 'bunbot'
const bb = new Bunbot()
// Type a string
bb.type('Hello world!')
// Tap a key
bb.tap('i', 'alt', 'command')
```
### Screen
```ts
import Bunbot from 'bunbot'
const bb = new Bunbot()
// Get screen size
const screenSize = bb.getScreenSize()
// Get mouse pos's color
const color = bb.getMousePositionColor()
// Get scale size
const scaleSize = bb.getScaleSize()
```
## Development
[View instructions](/Development.md)
## License
MIT

Sorry, the diff of this file is not supported yet