Wednesday 16 December 2015

Looking for a method to listen for an event(variable change or keypress)

I'm a noob. I've been looking for a method to listen for a clipboard paste change for a while, but had no luck, found lots of methods that don't work though!I want to create a daemon that snatches the user's clipboard and puts the contents in a database.Looked through node events but found nothing of interest, and found this snippet that listens for key events but only if the application runs in the foreground. My application will run as a daemon.var keypress = require('keypress'); // make `process.stdin` begin emitting "keypress" events keypress(process.stdin); // listen for the "keypress" event process.stdin.on('keypress', function (ch, key) { console.log('got "keypress"', key); if (key && key.ctrl && key.name == 'c') { process.stdin.pause(); } }); process.stdin.setRawMode(true); process.stdin.resume(); This is the snippet that I have currently:var copier = function (callback) { cboard.paste(function (err, data) { if (err) { console.log("Something happened!"); callback(err); } callback(data); }); }; copier(function (data) { console.log("This is the clipboard:" + data); }) It's using the copy-paste npm module. It works! Once.I'm going to continue trying things on my own, but any help would be greatly appreciated!Thank you

Submitted December 16, 2015 at 07:41PM by __-_-_-_-__-_-_-_-

No comments:

Post a Comment