UNPKG

click.js

Version:

Subscribe to system mouse/keyboard events.

108 lines (85 loc) 2.62 kB
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! ```js 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 ```js var clickjs = require('click.js') ``` ## Create ```js var click = new clickjs() ``` ## Methods A clickjs object exists of three methods. * start() * done() * on() ### Start Start listening. ```js click.start() ``` ### Done Kill the child. ```js click.done() ``` ### On Subscribe to events. ```js 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. ```js 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. ```js click.on('*', (event) => { // this event can be anything! but not an error }) ``` <img src="http://33.media.tumblr.com/avatar_048a728a1488_128.png"><hr/> # Jochem Stoel Involuntary public figure. <ul> <li> https://www.npmjs.com/~jochemstoel</li> <li> http://jochemstoel.github.io/</li> <li> https://jochemstoel.tumblr.com/</li> <li> https://jochemstoel.nl/</li> <li> https://www.facebook.com/Jochem-Stoel-271292656217087/</li> <li> https://www.quora.com/profile/Jochem-Stoel</li> </ul>