5

Can you get system wide keypress events and/or mouse movement events in nodejs? Thanks!

Shaun
  • 1,581
  • 2
  • 16
  • 35
  • 2
    I just posted an answer on [this question](http://stackoverflow.com/q/15231713/586621) that may be what you want. – Jay Jan 12 '14 at 22:02
  • That might work if you could couple it with: https://code.google.com/p/jnativehook/ since that seems to handle the platform specific issues Andrey noted. – Shaun Jan 13 '14 at 22:56

4 Answers4

2

I ended up writing a system specific application to do this that send the reply back over a local socket connection and using node's ability to exec processes and detect the OS to determine which version to launch. I think the comment to this being very system specific is the issue here.

Hopefully either node or the node-webkit folks through Chromium's ability to this will include it in node-webkit. Hope this helps someone in the future and thanks to everyone who tried to help!

Shaun
  • 1,581
  • 2
  • 16
  • 35
1

This very platform specific. If you are using X Window you can grab keyboard/mouse using node-x11 client

Andrey Sidorov
  • 24,905
  • 4
  • 62
  • 75
  • Check out the node-webkit tag, because they are a combination of chromium and nodejs I am hoping for a solution from one of those camps. And while the problem set itself is for sure platform specific, I am hoping someone else has taken care of that for me inside of either of these projects already. Thanks! – Shaun Jan 13 '14 at 22:44
  • you can use node.js modules from within node-webkit - and if you are using X it should be possible to leverage node-x11 to capture keyboard/mouse system wide – Andrey Sidorov Jan 14 '14 at 01:24
  • In this case I am mainly looking to handle events in Mac OS X and Windows. – Shaun Jan 16 '14 at 06:41
0

You can use node-java at least for mouse control. See this https://stackoverflow.com/a/21080830/578181

Community
  • 1
  • 1
Petre Tudor
  • 43
  • 1
  • 8
-2

That would not be NodeJS as that is server side. Use plain Javascript such as the Keypress lib or some jQuery. If you want your server to react based on this you'll need to make an Ajax call or use something like SocketIO (real time interaction between server/client)

Edit: I just saw that you tagged it node-webkit. I'm a little unclear if you need the kepress to reach server. Either way the above libs should do the trick.

cyberwombat
  • 38,105
  • 35
  • 175
  • 251
  • So with node-webkit as I understand it you get a nodejs server locally so system wide stdin or keyboard events could then be used to control you client application which is what I am looking. As I understand it keypress and jQuery can only act in context of the application, but I need something such that if the user walks away from the computer for 10 minutes it idles them out and vice versa if they don't interact with the app for 10 minutes and instead do something else on their machine it doesn't produce a false positive and idle them out incorrectly. – Shaun Jan 13 '14 at 22:24