Getting cursor position in Python
Using the standard ctypes library, this should yield the current on screen mouse coordinates without any third party modules:
from ctypes import windll, Structure, c_long, byref
class POINT(Structure):
_fields_ = [("x", c_long), ("y", c_long)]
def queryMousePosition():
pt = POINT()
windll.user32.GetCursorPos(byref(pt))
return { "x": pt.x, "y": pt.y}
pos = queryMousePosition()
print(pos)
I should mention that this code was taken from an example found here So credit goes to Nullege.com for this solution.
win32gui.GetCursorPos(point)
This retrieves the cursor's position, in screen coordinates - point = (x,y)
flags, hcursor, (x,y) = win32gui.GetCursorInfo()
Retrieves information about the global cursor.
Links:
- http://msdn.microsoft.com/en-us/library/ms648389(VS.85).aspx
- http://msdn.microsoft.com/en-us/library/ms648390(VS.85).aspx
I am assuming that you would be using python win32 API bindings or pywin32.
You will not find such function in standard Python libraries, while this function is Windows specific. However if you use ActiveState Python, or just install win32api
module to standard Python Windows installation you can use:
x, y = win32api.GetCursorPos()