Trigger some action on Ctrl-Right Click on Desktop ( using JAVA )
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 c开发者_运维百科an I write such an application.
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.
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ó.
精彩评论