0

My program is a distributed software for a small laboratory. It is written in java but because during daytime the computers are used, I have to manually restart it in the evening. I would solve the problem by starting it from a service every time the computer is started but I need a mechanism to detect: 1) user input(mouse, keyboard etc.) 2) user logon

Detecting any user input from java it is not possible. Is there any framework for something like this?

dan
  • 1
  • 1
    Have you considered running it as a daemon and scheduling it to start and stop when desired? – Andy Thomas Feb 21 '11 at 14:45
  • Anyhow - detecting user input directed to other programs is not supposed to be possible - it would be a major security hole. Would a timed service (between 20:00 and 04:00 for example) be acceptable? – extraneon Feb 21 '11 at 14:46
  • 1
    Couldn't you just leave it running at minimum priority, also during daytime? – Erik Feb 21 '11 at 14:47
  • there are hours during daytime when the labs are free and i don't know them. – dan Feb 21 '11 at 14:52
  • the best solution i found is getting the user activity using JNA. Using this it is possible to compute user idle time. – dan Mar 28 '11 at 12:47

1 Answers1

2

Detecting user input from Java is possible, but not with standard tecnologies. Considering the excellent example of aTunes, you can do it using, depending upon your platform

Considering your other question, I would use native abilities of client OSes to better handle your problem. First thing is to make your Java process lower priority. This way, it will run all time long, without having the user blocked by it. I would also force this program to stop when CPU load is over a given target. This can be achieved using JMX, as this previous question explains.

Community
  • 1
  • 1
Riduidel
  • 22,052
  • 14
  • 85
  • 185
  • I fully agree with the CPU load approach. After all, the computer might be doing something important even when no key is pressed. – biziclop Feb 21 '11 at 15:26