How to set mouse position?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

lukasbalaz
Posts: 4
Joined: Mon Nov 05, 2012 4:23 pm

How to set mouse position?

Postby lukasbalaz » Mon Nov 05, 2012 4:41 pm

I use Blender 2.64a and I need set mouse position and I don't know it.
Can you help me, please?

(Sorry for my English. I'm Slovak)

Jarmade
Posts: 4
Joined: Sat Nov 03, 2012 10:12 pm

Re: How to set mouse position?

Postby Jarmade » Mon Nov 05, 2012 6:13 pm

Not sure if blender has a built in way to do this, but this example only works on windows:

Code: Select all

import bpy
from ctypes import *

# point structure definition
class POINT(Structure):
   _fields_ = [("x", c_ulong), ("y", c_ulong)]

# Gets cursor position (windows only)
def getCursorPos():
   pt = POINT()
   windll.user32.GetCursorPos(byref(pt))
   return pt.x, pt.y

# Sets cursor position (windows only)
def setCursorPos(x, y):
   windll.user32.SetCursorPos(x, y)

# example
x, y = getCursorPos()
setCursorPos(x + 100, y)

lukasbalaz
Posts: 4
Joined: Mon Nov 05, 2012 4:23 pm

Postby lukasbalaz » Tue Nov 06, 2012 1:57 pm

I'm beginner python programmer and I don't know how to use Blender engine, too.
Can you write how to run this example, please?

Thanks.


Return to “Python”

Who is online

Users browsing this forum: No registered users and 2 guests