Solved

Detecting mouse and keyboard events

Posted on 2004-04-27
8
923 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 36
eclipse buid path vs tomcat lib path 10 37
What's wrong with this code? 4 34
Bot application - advice 3 58
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 Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

740 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