[haiku-development] Re: Obtaining mouse button type
- From: "Axel Dörfler" <axeld@xxxxxxxxxxxxxxxx>
- To: haiku-development@xxxxxxxxxxxxx
- Date: Mon, 09 Jun 2008 08:47:45 +0200 CEST
James Kim <jkim202@xxxxxxxxxxxxxxxxx> wrote:
> Hi! I have come across another problem with mouse event handling. I
> need
> to find out what button (left, right or none) is being pressed while
> BView::MouseMoved(). I have looked at GetMouse() but I cannot figure
> out
> how to retrieve the button information from it because GetMouse()
> returns nothing. Any suggestions or a reference to an example would
> be
> very appreciated. Thank you.
It's always a good idea to have a look at existing sample code; for
example, we have tons of code in our repository that does this -- just
take smaller apps like Sudoku.
Anyway, since you are in MouseMoved() anyway, you shouldn't need to use
GetMouse(). Instead, you should have a look at the message that
triggered the mouse move, it contains more information that just what
has been passed to the method.
For example in SudokuView.cpp, in its MouseMoved() method you'll find
the following code:
int32 buttons = 0;
if (Looper() != NULL && Looper()->CurrentMessage() != NULL)
Looper()->CurrentMessage()->FindInt32("buttons", &buttons);
This is overly defensive (as the Looper() and CurrentMessage() would
only be NULL if your own code called that function directly), but
afterwards, you may find the B_{PRIMARY|SECONDARY|
TERTIARY}_MOUSE_BUTTON constants in "button" as described by Ryan.
Bye,
Axel.
- References:
- [haiku-development] Obtaining mouse button type
- From: James Kim
Other related posts:
- » [haiku-development] Obtaining mouse button type
- » [haiku-development] Re: Obtaining mouse button type
- » [haiku-development] Re: Obtaining mouse button type
- [haiku-development] Obtaining mouse button type
- From: James Kim