Detect position of mouse without dragging

I understand this can return the position when the mouse is dragging:

currentController = self.controller.view().window().windowController()
if currentController:
	tool = currentController.toolEventHandler()
	crossHairCenter = tool.valueForKey_("draggCurrent").pointValue()

But I’d like the position of the mouse when it’s not dragging as well?

In what context do you need that?

Trying to make a reporter (or selectTool) that always draws something at the mouse’s position.

That will be difficult as you are not notified when the mouse is moved (there is some code that should do that but is was broken). Here is a snippet that will give you the current mouse position. Use it in one of the drawing methods:

view = self.controller().graphicView()
mousePositionInWindowCoordinates = view.window().mouseLocationOutsideOfEventStream()
mousePositionInViewCoordinates = view.convertPoint_fromView_(mousePositionInWindowCoordinates, None)

I tried it, and it doesn’t work unless I drag then. Is there a way to disable the dragging behaviour of the selectTool plugin then? i.e. preventing it from creating the marquee box and disabling the edit features?

1+ for disabling the marquee box (just curious)

And: how can one detect if a modifier key is pressed? E.g. the fn or opt key

I’d like to combine theses 2 things: draw something only when a modifier key is pressed and hiding the marquee box.

The problem is not that the above code is not working but that the view is not notified to redraw itself.

To disable the selection box, overwrite the drawSelection() method in the select tool. It is not possible to prevent it from within a reporter.

Thanks! And the modifier key question?

  1. How to overwrite it? Just adding a def drawSelection(self): pass to the reporter doesn’t do anything.
  2. Are you saying how to disable it, and then saying that it is not possible within a reporter? This is confusing, could you be a bit more specific please? :slight_smile:

I was speaking about the case when you would build a selection tool.

BTW: I found out the modifierFlags :slight_smile:

1 Like

How to make it so that it doesn’t select anything, def drawSelection(self): pass stops the marquee box from showing up but it still acts as as if something gets selected


selectAtPoint_withModifier_(self, aPoint, modifierFlag)


selectInRect_withModifier_(self, aRect, modifierFlag)

it works thanks!

What do you mean with breaks the tool?

The method is called like that because if you what to select something you are very much interested in the modifiers. In your case you overwrite both methods to disable the default behavior.

1 Like

Sorry it does work now I tried to edit my post but it’s still there

What is the argument to pass into the mouseDoubleDown_ method on currentController.toolEventHandler()
I’d like to get a notification from a double click.

Usually, you do not call that method yourself. If you have a good reason for it, and know what you are doing, please take a look at Apple’s Event Handling and NSEvent documentation.

Thanks, Rainer. I guess i wont harm anyone with what I try to do. Thanks for the hint.

Is it still not possible to remove the selection marquee from a reporter? Not even with super crazy CG hacking? I want it so hard to not be there in some cases.