• Post Reply Bookmark Topic Watch Topic
  • New Topic

get event from operating system  RSS feed

 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i need to get events from the operating system where my program is running on. i must know if the mouse is moved or a key is pressed. That means i want to know if the user is idle. but how can i know that if a other program has the focus?
i dont want to make my program operating system specific. is that possible?
thx a lot!
regards
kay
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the java.awt.Robot class. It should do everything you want. Don't expect it to work in an Applet though.
 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, but i dont wont to generate an event, i wont to know if an event was performed (by OS). It seems to me that the Robot class only can generate an event...
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right. I was thinking you could get the system event que from it. Umm, seems like there should be a way to do this. But I'm not sure at the moment.
 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any other ideas?
thx!!
 
Bob Sullivan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you app uses swing you can create inner classes or have your frame implement WindowListener, KeyListener and MouseListener. The methods in WindowListener you are interested in are windowActivated & windowDeactivated. You'll want KeyListener keyPressed and MouseListener mouseMoved as well. To determine that you app has lost all focus you will have to keep track of the state of all your open windows and when one goes inactive test to see if any others have gone active - if not they must have clicked on another app.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!