Q:

Where is interface between button click and event raising defined

When I click on button, might be in windows apps, web apps, etc it has some animation to actually see it clicked and event is raised in background. I've knowledge of events and its attaching to button click events but I wanted to know how this mechanism works. I always assumed it is inbuilt in operating systems.

A:

The mouse hardware sends very simple messages on the USB bus when appropriate, essentially "button x was pressed/released" and "moved this much in the x and y directions since the last message I sent."
The USB driver on the computer has either been polling for these messages (checking periodically), or receives an interrupt, which is a mechanism built into the hardware that says, "I have a new USB message so I'm running code at a particular location."
The USB driver passes the message to the mouse driver in the kernel.
The mouse driver passes the message to the graphics subsystem (like xorg on Linux).
The graphics subsystem keeps track of the absolute position of the mouse, updating it from the relative position messages the mouse driver sends.
The graphics subsystem passes events to the window manager (like mutter).
The window manager keeps track of which window is under the mouse, and passes click events to the windowing toolkit (like Qt) associated with that window.
The windowing toolkit keeps track of which button is under the mouse, performs the click animation using graphics primitives, and passes events to subscribed listeners.

Obviously the implementation is different for different operating systems.  In particular Windows lumps a lot of the layers together for the programmer and user point of view, but that's the basic lay of the land.  I gave you some names for Linux because those are open source and if you were so inclined you could trace everything from the silicon on up.  Qt and other widget toolkits, which seems to be the part you're most interested in, are also available for Windows.
It's pretty amazing to contemplate the precise flow of electrons needed starting at the mouse button switch, through the CPU, out to the Internet and back through countless routers and servers, back through your CPU, eventually resulting in every single pixel on your display being commanded to its own specific color.  We sum up that result of millions of hours of collaborative effort simply as "clicking a link."

