3

My main aim is to count the number of mouse clicks on a particular application.

Imagine I have opened Microsoft Word and a web browser on my PC. My Java code should tell me how many times I clicked on Word and on the web browser. I need the application name and the number of clicks.

How can I do this? Any solution must work for MAC, Linux and Windows.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Manoj
  • 3,947
  • 9
  • 46
  • 84
  • 1
    This topic might give you the (unfortunate) explanation u need: http://stackoverflow.com/questions/4869294/detecting-a-mouse-click-anywhere-on-screen-with-java – voluminat0 Nov 08 '12 at 14:44
  • I made something like you want in C#, you can use [mono project](http://www.mono-project.com/Main_Page) to run it over the platforms other than windows. I'm at work now so I can't access my sources but if you are interested I can search for it after. – HericDenis Nov 08 '12 at 15:12
  • Thanks friend. i want only java.i dnt know we can do in java or not?.You will found send me yar.. – Manoj Nov 09 '12 at 05:15
  • @HericDenis : Friend can you please send example in c#.. – Manoj Nov 09 '12 at 07:00
  • Sure I do @Manoj, actualy I think my software made something like send clicks to programs but I think it won't be hard to do the other way. Unfortunally I can't do it now since I'm at work, so ASAP I'll try out an example for you. – HericDenis Nov 09 '12 at 10:24
  • @HericDenis: Thanks ya lot.. if its not possible here, you can post me to my mail mahesh.sivasamy@gmail.com – Manoj Nov 09 '12 at 11:20
  • Okay @Manoj (: I hope this kind of stuff was implemented in mono for MAC and Linux as it works for standard .NET – HericDenis Nov 09 '12 at 14:45
  • @HericDenis: Thanks friend. I'm waiting for you code... it’s possible in java any idea? – Manoj Nov 10 '12 at 06:16
  • @HericDenis: R u there?.. i'm waiting for your code.. – Manoj Nov 19 '12 at 04:06
  • Oh @Manoj I'm sorry! I really forgot that ;D I'm at work now (just started) it's 7:40 AM here, I'll leave 4:30 PM and then I can look for your code (: – HericDenis Nov 19 '12 at 09:39
  • Yeah @Manoj I forgot that again, I'm on a rush here :/ – HericDenis Nov 20 '12 at 11:59
  • @HericDenis:kindly send where ever your free.. but iits urgent. – Manoj Nov 21 '12 at 05:31
  • Sorry @Manoj but I've got an internship report to finish until friday so I'm a bit busy now; I know that's a long time since I said but I really hadn't time for that. You're still trying another solution, right? – HericDenis Nov 27 '12 at 14:41
  • @HericDenis: Thanks ya ... now i leaved thats task.. if u done once send me... give me your personal gmail id for we will chat in there... – Manoj Dec 19 '12 at 04:34

1 Answers1

6

You could try a library such as jnativehook: http://code.google.com/p/jnativehook/. Check out their examples on this page.

This library uses native functionality to provide access to mouse events that would otherwise be impossible to achieve in pure Java. It appears to support Mac, Linux and Windows.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • Thanks, Dunkan. This library is exactly what I was looking for. – AlexR Nov 08 '12 at 14:46
  • Thanks for your reply. I know jnativehook jar is to get all mouse event information. But i dint found any source to get the application name where the mouse is clicked currently by the user. – Manoj Nov 09 '12 at 04:47
  • her i was tired following infomration got when i click on my mouse java.awt.Point[x=543,y=730] | java.awt.FocusEvent[FOCUS_GAINED,permanent,opposite=null,cause=ACTIVATION] on javax.swing.JFrame[frame0,0,0,158x45,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,9,36,140x0,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true] – Manoj Nov 09 '12 at 04:48