Solved

Detecting mouse and keyboard events

Posted on 2004-04-27
8
919 Views
Last Modified: 2008-02-01
Hi

I'm using JDK 1.4 and SWT to build an application.
Is there a way of detecting mouse and keyboard events on the operating system level in Java?

I want to detect if the user has not used the mouse or the keyboard for five minutes and trigger
an event in that case.

I'm quite sure this is not possible but has anyone tried to do the same?

Mbutu
0
Comment
Question by:mbutu
8 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 20 total points
ID: 10935750
not possible without using native code and JNI
0
 

Author Comment

by:mbutu
ID: 10936223
And there is no library I can download or feature of SWT I can use?
0
 
LVL 9

Assisted Solution

by:mmuruganandam
mmuruganandam earned 20 total points
ID: 10936332
There is no such native API in SWT as I know.

You have to write your own DLL to do that otherwise.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 30

Expert Comment

by:Mayank S
ID: 10938133
Yup, you need native code for that.
0
 
LVL 16

Accepted Solution

by:
gnoon earned 65 total points
ID: 10945937
I think you can with jdk 1.5 by the java.awt.MouseInfo class. The trick is get mouse location every n secs by thread, if it's the same location in five minite then trigger an event.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10946154
But remember that 1.5 is still in the beta version....
0
 

Author Comment

by:mbutu
ID: 10946240
Ok. java.awt.MouseInfo seems to be good enough. If I need to know if the mouse is idle.
But I also have to know if the keyboard is idle. I guess there's nothing in JDK 1.5 for that.

0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 20 total points
ID: 10946379
As far as I know, MouseInfo has methods getNumberOfButtons () and getPointerInfo (). getNumberOfButtons () is not needed for your case. Using the static getPointerInfo () method, you get a PointerInfo () object which has a getLocation () method to return you the Point object containing the current co-ordinates of the mouse. But the question remains - how will you call this method when a mouse-click happens outside your application? You cannot capture that mouse-click still.... using these co-ordinates, you can just know if the mouse is currently positioned outside your GUI or not. But how will you detect the click?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet filter example 37 63
jdbc error in jsp application 20 46
iterator/ListIterator approach 17 28
throw exception 21 44
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question