Solved

Detecting mouse and keyboard events

Posted on 2004-04-27
8
917 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
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10938133
Yup, you need native code for that.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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:mayankeagle
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:mayankeagle
mayankeagle 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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:

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now