Re: Getting the position of the mouse
Re: Getting the position of the mouse
- Subject: Re: Getting the position of the mouse
- From: Marco Binder <email@hidden>
- Date: Sun, 17 Nov 2002 12:12:58 +0100
Have you ever tried, what Cristian suggested? According to the docs,
this method is even a class-method, so try: [NSEvent mouseLocation]...
this should give you the current mouse location.
BTW, your code CANT really work, as far as I see, since your event is a
-> keyUp <- event, so how can you ask for the CLICK position?
locationInWindow will return the location of the view receiving the key
event in that case; which for you is your window!
No, it's not that simple !
Well, dont be too sure bout that and just try what I say above!
marco
Am Freitag, 15.11.02 um 09:20 Uhr schrieb Cristi Savu:
No, it's not that simple !
Look what I'm trying to do :
- I'm popping up a menu at mouseDown on a view.
- if the user pressed ESCAPE, the menu disappears but since that
moment, my beloved view doesn't receive
mouseMoved events anymore. So, I need to make it first responder again
only if the mouse is still inside.
- Because of that, I'm capturing keyUp, and I'm performing my first
responder mambo-jambo in there.
- this is the code, if anybody has a slightest idea, please let me
know.
(BTW, not receiving mouseMoved anymore after a context menu is
dismissed is a cocoa bug, if anybody from there reads this)
- (void)keyUp:(NSEvent *)theEvent
{
NSString * tString;
unichar tChar;
tString= [theEvent characters];
NSLog(@"Key pressed");
tChar=[tString characterAtIndex:0];
if (tChar == 27)
{
NSPoint clickPoint = [theEvent locationInWindow];
NSPoint aPoint = [self convertPoint:clickPoint fromView:nil];
NSLog(@" Escape Pressed ! The mouse is at : %f,
%f",clickPoint.x, clickPoint.y); // NOPE IT IS NOT,
// clickPoint contains the origin of my window
// main window is first respoder
[[self window] setAcceptsMouseMovedEvents: NO];
[[self window] makeFirstResponder:[self window]];
// NEVER INSIDE
if (NSPointInRect(aPoint, [self bounds]))
{
NSLog(@"Escape Pressed ! AND THE MOUSE IS INSIDE");
// my view is first respoder
[[self window] setAcceptsMouseMovedEvents: YES];
[[self window] makeFirstResponder:self];
}
// else
// NSLog(@" Escape Pressed ! AND THE MOUSE IS OUTSIDE");
}
[[self window] resetCursorRects];
[[self window] invalidateCursorRectsForView:self];
}
On Friday, November 15, 2002, at 09:36 AM, Charles Srstka wrote:
I think it's [[NSApp currentEvent] mouseLocation];
HTH,
Charles
On Thursday, November 14, 2002, at 04:45 AM, Cristi Savu wrote:
How can I get the position of the mouse at any time in an
application ?
I need to know the position of the mouse while I am inside keyUp
of keyDown and
the event received by these methods doesn't contains a valid mouse
position.
Regards, Cristian
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.