Determine if the cursor is over Tools shelf, Properties shelf or 3D content
There is a context.region.type variable which can have the following values:


WINDOW - 3D View
UI - Properties Panel
TOOLS -  Tool Panel
values for the other possible regions (see the documentation)


However context.region.type seems to be determined once on operator invokation. So it will always have the same value while a modal operator is running. The only way seems to be to find out manually:

for region in context.area.regions:
    if(region.x &lt;= event.mouse_x &lt; region.x + region.width  and
       region.y &lt;= event.mouse_y &lt; region.y + region.height and
       region.type in ("TOOLS", "UI")):
        #
        return {'PASS_THROUGH'}


Perhaps a more appropriate way would be to check if the cursor is over the  3D View:

for region in context.area.regions:
    if(region.type == "WINDOW" and
       region.x &lt;= event.mouse_x &lt; region.x + region.width and
       region.y &lt;= event.mouse_y &lt; region.y + region.height):
        break
else:
    return {'PASS_THROUGH'}