click.js

0.0.8 • Public • Published

Click.js will detect mouse and keyboard events using a tiny child process and allow you to subscribe to the event loop using Node. It also detects switching between windows and changes made to the clipboard. (Click.js is Windows only)

First an example

Easy as pie!

var clickjs = require('click.js')
var click = new clickjs()
 
click.on('keyInput', (event) => {
    console.log(event) // event contains details
})
 
click.start()
setTimeout(() => {
    click.done() // for sake of example, stop listening after 60 seconds
}, 60000)

Require

var clickjs = require('click.js')

Create

var click = new clickjs()

Methods

A clickjs object exists of three methods.

  • start()
  • done()
  • on()

Start

Start listening.

click.start()

Done

Kill the child.

click.done()

On

Subscribe to events.

click.on(type, callback(event))

Types

There are 5 event types with consistent properties.

  • keyInput (a key is pressed or released)
  • mouseInput (any mouse button is pressed or released)
  • clipboardModified (windows clipboard has been overwritten)
  • applicationWindowChange (user changed active window)

keyInput

A key on the keyboard is pressed or released.

mouseInput

A mousebutton contains the event (sub)type as well as the coordinates.

clipboardModified

In most cases the user has pressed ctrl+c.

applicationWindowChange

A window is minimized or whatever.

Event loop

Subscribe to events using simple on-method.

mouseInput

Subscribe to all mouse events. Mouse events include button down, button up, scrolling and cursor movement.

click.on('mouseInput', (event) => {
    console.log(event) // event also includes event type
})

Subscribe to other events

Subscribe to any of the 5 event types and console.log the event to see what info that gives you.

Subscribe to all available event types

This will not override the behavior of type specific callbacks but they will both be called.

click.on('*', (event) => {
    // this event can be anything! but not an error
})


Jochem Stoel

Involuntary public figure.

  • https://www.npmjs.com/~jochemstoel
  • http://jochemstoel.github.io/
  • https://jochemstoel.tumblr.com/
  • https://jochemstoel.nl/
  • https://www.facebook.com/Jochem-Stoel-271292656217087/
  • https://www.quora.com/profile/Jochem-Stoel

Package Sidebar

Install

npm i click.js

Weekly Downloads

0

Version

0.0.8

License

ISC

Last publish

Collaborators

  • jochemstoel