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.