How to get a right click coordinates in 3d_view I'm listening to the right click in my model operator. I wish to get its 3D coordinates in the 3D_view. I've tried the following code from here:
from bpy_extras.view3d_utils import region_2d_to_vector_3d, region_2d_to_location_3d
def mouse_coo_to_3d_loc(event, context):
    coord = (event.mouse_region_x, event.mouse_region_y)
    region = context.region
    rv3d = context.space_data.region_3d
    vec = region_2d_to_vector_3d(region, rv3d, coord)
    return region_2d_to_location_3d(region, rv3d, coord, vec)

But I got different coordinates from bpy.context.scene.cursor_location. I thought that maybe the context is wrong, so I used this code instead:
def mouse_coo_to_3d_loc(event):
    area, region = get_3d_area_region()
    coord = (event.mouse_x - area.x, event.mouse_y - area.y)
    rv3d = area.spaces.active.region_3d
    vec = region_2d_to_vector_3d(region, rv3d, coord)
    return region_2d_to_location_3d(region, rv3d, coord, vec)

def get_3d_area_region():
    for screen in bpy.data.screens:
        for area in screen.areas:
            if area.type == 'VIEW_3D':
                for region in area.regions:
                    if region.type == 'WINDOW':
                        return area, region

But still wrong results. Am I m missing something here?
**** EDIT ****
I should have mentioned that my addon is running in the graph_editor.
Get screen from context.screen or context.window.screen

Get the clicked area by looking at area coordinates, of each area, in the screen returned from context.screen or context.window.screen. Used the latter in example below, my tests suggest could use either.   The region can be obtained from the area.  

    if event.type == 'RIGHTMOUSE' and event.value == 'PRESS':
        screen = context.window.screen # or context.screen
        def get_click_area():            
            for a in screen.areas:
                if (a.x &lt; event.mouse_x &lt; a.x + a.width
                and a.y &lt; event.mouse_y &lt; a.y + a.height):
                    return a
        a = get_click_area()
        print("Right Clicked in %s area of screen %s" % (a.type, screen.name))


as mentioned in my comment, get_3d_area_region() above, will only return the first matching area it finds in the bpy.data.screens collection. For the default file will be bpy.data.screens["3D Full View"].areas[1] every time.