tags:

views:

27

answers:

2

I need to write one JAVA application. The requirement is ,

when the user clicked anywhere in the screen ( It may be upon an icon in Desktop or upon one word in Microft word ) , my java program should be notified to do some action.

How can I write such an application.

+2  A: 

You are talking about creating a system wide hook (windows API call SetWindowsHookEx with WM_MOUSE or WM_MOUSELL). This is not for the faint of heart. Doing this for a single process that you own is a bit tricky. Doing it system-wide (for processes that you don't own) is really, really tricky - lot's of pitfalls (I'm pretty sure I've hit every single one), and this is one severely under-documented area of the Win32 API.

This will absolutely require using the Windows API, as well as DLLs, an understanding of injection of DLLs into different processes and a host of other things. Java isn't going to get this particular job done (in fact, based on your specification, I can't imagine why Java would be the language of choice here).

Time to break out the C.

Kevin Day
A: 

Java doesn't have any standard functionality allowing this. You must talk directmy to Windows using JNI or JNA, or use a third party library doing that.

For this particular purpose a Microsoft language would probably be best, but it is still a very tricky thing to have to dó.

Thorbjørn Ravn Andersen