?
Solved

Detecting mouse and keyboard events

Posted on 2004-04-27
8
Medium Priority
?
930 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 60 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 60 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 30

Expert Comment

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

Accepted Solution

by:
gnoon earned 195 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 60 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

850 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