as far as I’m aware it’s not possible to get the mouse position without an event. knowing that it’s just python you’re running on- you can use pretty much any method you like- you’ll just have to convert the screen coordinates into relevant data you can use in Blender (relative to region coordinates, etc).
@sybren I’m not sure what OP is trying to do, but one example I’ve used this for in the past is knowing what the precise mouse position was at the time a menu was invoked (by hijacking the poll function), so operators can raycast from the ‘position of intent’ rather than wherever the menu button happened to appear on the screen.
Sorry, I didn’t make it clear. I want to draw the grid in the 3D view and obtain the mouse position to locate the mouse position in the 3D view. Just like the tool ‘add Cube’, I can draw the grid in the mouse position, but it doesn’t enter the mode