# macmouse

> Enables you to create virtual mouse input on Mac OS X using Cocoa.

Latest version **1.2.1** (published 2016-08-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install macmouse
pnpm add macmouse
yarn add macmouse
bun add macmouse
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2016-08-18 |
| First published | 2014-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Sveinn Floki Gudmundsson |
| Maintainers | loknar |
| Keywords | native mouse, mac os x |

## Links

- npm: https://www.npmjs.com/package/macmouse
- Repository: https://github.com/Loknar/node-macmouse
- Homepage: https://github.com/Loknar/node-macmouse#readme
- Issues: https://github.com/Loknar/node-macmouse/issues
- npm.io page: https://npm.io/package/macmouse

## Dependencies (1)

- [nodobjc](https://npm.io/package/nodobjc.md) 2.1.0

## Recent versions

- 1.2.1 (latest) — 2016-08-18
- 1.2.0 — 2015-06-27
- 1.1.0 — 2015-06-23
- 1.0.0 — 2015-04-13
- 0.0.2 — 2014-09-05
- 0.0.1 — 2014-08-28

## README

# macmouse

[![NPM](https://nodei.co/npm/macmouse.png)](https://www.npmjs.com/package/macmouse)

A node.js module that enables you to create virtual mouse input on Mac OS X.

## Credits
Uses [NodObjC](https://github.com/TooTallNate/NodObjC) to hook into the Cocoa framework. The macmouse module is merely a wrapper around mouse control commands to the Cocoa framework via NodObjC.

## Installation

Install using `npm`,

``` bash
$ npm install macmouse
```

## Usage Example
``` javascript
var mouse = require('macmouse');

mouse.init();

var ptX = 800;
var ptY = 600;

var counter = 0;

var doThings = function() {
    mouse.Place(ptX, ptY);
    setTimeout(pressAndHold, 250);
}

var pressAndHold = function() {
    mouse.LeftButtonPress();
    setTimeout(doDragStuff, 250);
}

var doDragStuff = function() {
    ptX += 2;
    ptY += 2;
    mouse.DragPlace(ptX, ptY);
    if (counter < 15) {
        counter += 1;
        setTimeout(doDragStuff, 250);
    }
    else {
        mouse.LeftButtonRelease();
    }
}


doThings();

mouse.quit();

```

## List of functions

And a small description for each function.

``` javascript
// Desc:   Imports the macmouse module as mouse
// Before: nothing
// After:  mouse is an uninitialized macmouse
var mouse = require('macmouse');
```

### init

``` javascript
// Desc:   Initializes the macmouse module
// Before: mouse is an uninitialized macmouse
// After:  mouse is an initialized macmouse
mouse.init();
```

### getRealPos

``` javascript
// Desc:   Sends request for real mouse position, more expensive than getPos
// Before: mouse is an initialized macmouse
// After:  pos holds x and y numbers representing the system mouse position
var pos = mouse.getRealPos();
var x = pos.x;
var y = pos.y;
```

### getPos

``` javascript
// Desc:   Returns mouse position currently stored in the mouse module
// Before: mouse is an initialized macmouse
// After:  pos holds x and y numbers representing the system mouse position currently stored in the
//         mouse module
var pos = mouse.getPos();
var x = pos.x;
var y = pos.y;
```

### Place

``` javascript
// Desc:   Sends mouse event message to place the system mouse at a specific position
// Before: mouse is an initialized macmouse, x and y are numbers representing a specific position
// After:  mouse event has been sent to move the system mouse to position defined by x and y
mouse.Place(x, y);
```

### DragPlace

``` javascript
// Desc:   Sends mouse event message to place the system mouse at a specific position while in a 
//         dragging state
// Before: mouse is an initialized macmouse, x and y are numbers representing a specific position, the 
//         system mouse currently has (or thinks it has) the left mouse button pressed
// After:  mouse event has been sent to move the system mouse to position defined by x and y with left 
//         mouse button pressed
mouse.DragPlace(x, y);
```

### Move

``` javascript
// Desc:   Sends mouse event message to move the system mouse (from current stored position in the mouse 
//         module) by a vector defined by dx and dy
// Before: mouse is an initialized macmouse, dx and dy are numbers representing our moving vector 
// After:  mouse event has been sent to move the system mouse by a vector defined by the numbers dx and dy
mouse.Move(dx, dy);
```

### DragMove

``` javascript
// Desc:   Sends mouse event message to move the system mouse (from current stored position in the mouse 
//         module) by a vector defined by dx and dy while in a dragging state
// Before: mouse is an initialized macmouse, dx and dy are numbers representing our moving vector, the 
//         system mouse currently has (or thinks it has) the left mouse button pressed
// After:  mouse event has been sent to move the system mouse by a vector defined by the numbers dx and dy 
//         with left mouse button pressed
mouse.DragMove(dx, dy);
```

### LeftButtonPress

``` javascript
// Desc:   Sends mouse event message to press and hold down the left button of the system mouse
// Before: mouse is an initialized macmouse
// After:  mouse event has been sent to press and hold the left button on the system mouse
mouse.LeftButtonPress();
```

### LeftButtonRelease

``` javascript
// Desc:   Sends mouse event message to release a pressed left button of the system mouse
// Before: mouse is an initialized macmouse
// After:  mouse event has been sent to release a pressed left button on the system mouse
mouse.LeftButtonRelease();
```

### Click

``` javascript
// Desc:   Sends mouse event message to press and release left button of the system mouse
// Before: mouse is an initialized macmouse
// After:  mouse event has been sent to press and release left button on the system mouse
mouse.Click();
```

### RightButtonPress

``` javascript
// Desc:   Sends mouse event message to press and hold down the right button of the system mouse
// Before: mouse is an initialized macmouse
// After:  mouse event has been sent to press and hold the right button on the system mouse
mouse.RightButtonPress();
```

### RightButtonRelease

``` javascript
// Desc:   Sends mouse event message to release a pressed right button of the system mouse
// Before: mouse is an initialized macmouse
// After:  mouse event has been sent to release a pressed right button on the system mouse
mouse.RightButtonRelease();
```

### RightClick

``` javascript
// Desc:   Sends mouse event message to press and release right button of the system mouse
// Before: mouse is an initialized macmouse
// After:  mouse event has been sent to press and release right button on the system mouse
mouse.RightClick();
```

### DoubleClick

``` javascript
// Desc:   Sends mouse event message to double click the system mouse
// Before: mouse is an initialized macmouse
// After:  mouse event has been sent to double click the system mouse
mouse.DoubleClick();
```

### Scroll

``` javascript
// Desc:   Sends mouse scroll event message
// Before: mouse is an initialized macmouse, vertical and horizontal
//         are 'small signed integer values, typically in a range from -10 to +10',
//         in reality they can be any integer from -32768 to 32767,
//         if horizontal isn't provided it defaults to 0
// After:  scroll event has been sent to scroll by a vector defined by the
//         vertical and horizontal integers
mouse.Scroll(vertical);
mouse.Scroll(vertical, horizontal);
```

### quit

``` javascript
// Desc:   Does garbage collection on some objective c stuff, be a good lad and call this when 
//         you're done using the macmouse module
// Before: mouse is an initialized macmouse
// After:  mouse is an uninitialized macmouse
mouse.quit();
```

## License
(MIT License)

---
_Source: https://npm.io/package/macmouse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
