1
$\begingroup$

first, I mean to Operating System Cursor... NOT TO blender's 3d cursor

second... this location is different to ct.windll.user32.GetCursorPos(ct.byref(pt)), I think because blender made here own calculation from blender UI...

blender allow me to set the location of this "real" cursor using bpy.context.window.cursor_set, but.. how to get the actual location?

thanks

$\endgroup$
1
  • 2
    $\begingroup$ the location you set with cursor_set is relative to the blender window (bottom, left is 0,0 ) ;can you use event.mouse_x ? $\endgroup$
    – Chebhou
    Commented Mar 29, 2015 at 12:56

1 Answer 1

1
$\begingroup$

here an example http://www.blender.org/api/blender_python_api_2_57_release/bpy.types.Operator.html#invoke-function

import bpy


class SimpleMouseOperator(bpy.types.Operator):
    """ This operator shows the mouse location,
        this string is used for the tooltip and API docs
    """
    bl_idname = "wm.mouse_position"
    bl_label = "Invoke Mouse Operator"

    x = bpy.props.IntProperty()
    y = bpy.props.IntProperty()

    def execute(self, context):
        # rather then printing, use the report function,
        # this way the messag appiers in the header,
        self.report({'INFO'}, "Mouse coords are %d %d" % (self.x, self.y))
        print((self.x, self.y))
        return {'FINISHED'}

    def invoke(self, context, event):
        self.x = event.mouse_x
        self.y = event.mouse_y
        return self.execute(context)

bpy.utils.register_class(SimpleMouseOperator)

# Test call to the newly defined operator.
# Here we call the operator and invoke it, meaning that the settings are taken
# from the mouse.
bpy.ops.wm.mouse_position('INVOKE_DEFAULT')

# Another test call, this time call execute() directly with pre-defined settings.
bpy.ops.wm.mouse_position('EXEC_DEFAULT', x=20, y=66)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .