Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I listen for clipboard events in node.js?

I want to be able to listen for clipboard events (the copy event more precisely) in node.js.

I've already used windows keyboard hooks in java... so I'm already a bit familiar with the topic.

And as I'm using Ubuntu 10.10 as my main OS, I'm most interested in a Ubuntu Desktop solution. (but I'd still love to know how to accomplish this for a Windows system too)

Any thoughts?

Thanks a lot in advance,

Jochen

like image 886
prefabSOFT Avatar asked Dec 21 '11 03:12

prefabSOFT


2 Answers

I suggest you look at the node-clipboard module and continually listen for changes to the clipboard using callbacks. Something like:

var clipboard = ""
function listenClipboard(){
    var new_clip = getClipboard()
    if (new_clip !== clipboard) {
        clipboard = new_clip
        handleClipboardChange(clipboard)
    }
    setTimeout(listenClipboard, 100)
}
like image 76
theideasmith Avatar answered Sep 28 '22 04:09

theideasmith


You can try installing my npm package Use clipboard-event

const clipboardListener = require('clipboard-event');

    // To start listening
    clipboardListener.startListening();

    clipboardListener.on('change', () => {
        console.log('Clipboard changed');
    });

    // To stop listening
    clipboardListener.stopListening();

Thank you.

like image 31
Sudhakar Ramasamy Avatar answered Sep 28 '22 05:09

Sudhakar Ramasamy