Detecting user activity in other programs


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Detecting user activity in other programs

  1. #1
    Join Date
    Sep 2005
    Posts
    4

    Detecting user activity in other programs

    Iím doing now a program which measures user activity. That program is in background, but it should be able to tell if user is doing something on computer or not. Now Iím able to detect only mouse movements (by getting each second mouse X and Y and comparing them to precedent values) but how can I see if user is using only keyboard in other programs? Is there a way to do it in Java?

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Just as you have mouse events, you have keyboard events which your program can monitor. So the trick is creating an "EventListener" which can monitor and capture keyboard input even when your program does not have focus ... If you are doing this with mouse events, won't the same mechanism work for key events?

  3. #3
    Join Date
    Sep 2005
    Posts
    4
    Quote Originally Posted by nspils
    Just as you have mouse events, you have keyboard events which your program can monitor. So the trick is creating an "EventListener" which can monitor and capture keyboard input even when your program does not have focus ... If you are doing this with mouse events, won't the same mechanism work for key events?
    Do you think I would have asked this question if it were so simple?
    An window doesn't receive event's if it doesn't have focus, the only way to check mouse is like this:

    PointerInfo pi = MouseInfo.getPointerInfo();
    Point po = pi.getLocation();

    and compare new pointer with old one.
    Last edited by sergio; 09-09-2005 at 04:19 PM.

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Here is an article which seems to hold the kernel of how to approach your issue - using the JNI to interact with the operating system

    http://www.javaworld.com/javaworld/j...tmessages.html

    and

    http://www.devx.com/Java/Article/21841/1763/page/1

    Sun's JNI tutorial and other info can be found here:

    http://java.sun.com/docs/books/tutorial/native1.1/

    http://java.sun.com/j2se/1.4.2/docs/guide/jni/

    http://java.sun.com/developer/online...CBook/jni.html

  5. #5
    Join Date
    Sep 2005
    Posts
    4
    Quote Originally Posted by nspils
    Here is an article which seems to hold the kernel of how to approach your issue - using the JNI to interact with the operating system
    Nspils, thank you very much for answering my posts, but I was hoping that there is a cross platform Java solution to this problem.

  6. #6
    Join Date
    Jul 2005
    Location
    the Netherlands
    Posts
    128
    Quote Originally Posted by sergio
    Nspils, thank you very much for answering my posts, but I was hoping that there is a cross platform Java solution to this problem.
    I don't exactly know what you mean by "cross platform Java solution". I think you mean that you hope it would be possible with only Java. But I think nspils is right; for accessing the mouse or keyboard you'll need a more low level language, JNI would be an option for you to create native methods in Java.

  7. #7
    Join Date
    Sep 2005
    Posts
    4
    Quote Originally Posted by prometheuzz
    I don't exactly know what you mean by "cross platform Java solution". I think you mean that you hope it would be possible with only Java.
    Yes, that is correct.
    But I think nspils is right; for accessing the mouse or keyboard you'll need a more low level language, JNI would be an option for you to create native methods in Java.
    But I can access mouse with only Java. And if Sun created MouseInfo, why they have not created KeyboardInfo?

Similar Threads

  1. Detecting if a certain user is already online
    By Mehdi Mousavi in forum ASP.NET
    Replies: 0
    Last Post: 02-22-2002, 12:26 PM
  2. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 12:45 PM
  3. Detecting User ID
    By Michael in forum Web
    Replies: 0
    Last Post: 03-29-2001, 02:07 PM
  4. Replies: 2
    Last Post: 12-01-2000, 12:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center