This is called event driven programming. When a button is pressed, mouse moved or clicked or something happens, the event is caught by the main loop of the desktop GUI (Graphical User Interface) and passed to the main loop of your GUI program. Your program, if it's interested in this event (by registering this event with the desktop GUI), executes an event handler function which is called with the parameters of the event (mouse location, which key was pressed). In your case, the mouse-down event might trigger a function that draws a curved (smiley) line, and the mouse-up event might draw a straight line.