Raphael - mouse events - raphael

How would you determine what mouse buttons was clicked on a mouse event?
I would like to make the distinction between left and right click.

I am not sure about the click event (though it may be worth a try) but if you use the mousedown event which should be good enough, then you can check the "which" property of the event.
The which property is an integer that determine the mouse button, and the values are mapped like...
1 = Left Button
2 = Middle Button
3 = Right Button
Example code...
element.mousedown(ElementMouseDown);
function ElementMouseDown(e) {
switch(e.which){
case 1://left button
break;
case 2://middle button
break;
case 3://right button
break;
}
}

Related

WM_LBUTTONUP message only working as a double click

I have a ListView Control with a LVS_REPORT style set. The thing I want is that when I click the row of an item, doesn't matter where it is, even if it's above a subitem, the item gets selected. Currently, the ListView only detects clicks over the first column (item) to make the selection.
To do this, I tried to handle the WM_LBUTTONUP message, so when the user releases the left mouse button on the row rectangle, it selects the corresponding item. It could work, but currently it needs a double click to do the selection.
This is the code that goes in the subclass window procedure:
case WM_LBUTTONUP:
{
long x = GET_X_LPARAM(lParam);
long y = GET_Y_LPARAM(lParam);
RECT rc{};
Message("btn up"); // message box that shows when the left button is released
for (auto& item : lst->m_items)
{
ListView_GetItemRect(lst->handle(), item->index, &rc, LVIR_BOUNDS);
POINTS p;
if (PtInRect(&rc, { x, y })) // checks if clicked point is inside the item rect
{
ListView_SetItemState(lst->m_hwnd, item->index, LVIS_SELECTED, 7);
break;
}
}
return 0;
}
The same code (except the loop part) I put inside an Edit subclass procedure and the Main Window subclass procedure. Both work as intended, that is, when a hit a single click, it shows a message.
Is there a workaround for this? Couldn't find any style to achieve this objective, either. What could be causing this issue? I thought, for some reason, that either some other window could be above the ListView and that could be stopping it to receive new clicks or also it could be sending the click first to the parent window. These are not the case: 1) the control is not behind any other window; 2) if this was the case, the program would show a MessageBox with the message specified in the procedure, which doesn't happen.
Thanks in advance.

Label detection mouse click c++

I'm trying to build a simple API in c++. It detects which button of my mouse I click on my window and it shows a MessageBox saying which button was clicked. I also managed to show in a messageBox when I release the button of my mouse. But I can't use both at the same time.
It is possible, instead using messageBox, inserting text of which button was clicked in a label, and change it depending of which button was pressed/released?
I use a switch with differents cases for each button pressed/released. Tell me if you have something for me, would be appreciated. Can show my code if you want !
I managed to find a solution.
First declareda label.
#define ID_LABEL 1
static HWND myLabel;
Then created it.
case WM_CREATE:
myLabel = CreateWindow(TEXT("BUTTON"),TEXT("hello"),
WS_VISIBLE|WS_CHILD,50,50,150,25,
hwnd,(HMENU) ID_LABEL,NULL,NULL);
break;
And then for each button pressed/released, I edit the text. Example for when i press the left button of my mouse.
case WM_LBUTTONDOWN:
myLabel = CreateWindow(TEXT("BUTTON"),TEXT("left button pressed"),
WS_VISIBLE|WS_CHILD,50,50,150,25,
hwnd,(HMENU) ID_LABEL,NULL,NULL);
break;
And it's working. Is anyway a better way to do it ?

Register single mouse click (C++)

I have two if statements that both respond to my computer mouse.
if (GetAsyncKeyState(VK_LBUTTON))
{
//Do something
}
//More code in between
if (GetAsyncKeyState(VK_LBUTTON))
{
//Do something else
}
However, when I click the left mouse button once it is registered for both if statements. "GetAsyncKeyState" seems to return true as long as the mouse button is down (which it inevitably will be for the second if statement), so what should I use instead so that I need to actively click the mouse button a second time in order for the second statement to take effect?

C++ CLI GUI Event Handeling

I am working on a c++ CLI application and am having some difficulty with events. I am wondering if I can get events to fire while the mouse button is clicked. For example, I am wanting to check whether or not the mouse has moved to the next square over only if they have the mouse clicked in. Meaning if they click on square 1 they should be able to hold that click and move the square 2 and my program recognize this.
I have run a number of different events on the mouse, including the "Click" event, but the neither the hover, mouse enter, or mouse down event get triggered while the button is pressed. The "MouseClick" event, which does the same. I tried using just the mouseDown event, but this does not let another mouseDown event, mouse enter, or hover event fire.
Short of checking mouse position I do not know what I can do. I would like to not have to do mouse position checking.
If anyone has any ideas, they would be greatly appreciated.
Clearly you'll want to pay attention to the MouseMove event so you can see the mouse moving into another square. Roughly:
void panel1_MouseMove(Object^ sender, MouseEventArgs^ e) {
if ((e->Button & System::Windows::Forms::MouseButtons::Left) ==
System::Windows::Forms::MouseButtons::Left) {
int square = MapPosToSquare(e->Location);
if (square != currentSquare) {
currentSquare = square;
OnSquareClicked(currentSquare);
}
}
}
If these "squares" are actually controls then you have a different problem. You have to set the control's Capture property to false in the MouseDown event handler so it doesn't capture the mouse.

Win32 : How to trap left and right mouse button clicked at the same time

I am trying to program specific behaviour when the user (clicks and) releases the left and right mouse at the same time. Is there a known way to trap such an event / gesture. I am aware of how to trap leftButtonUp and rightButtonUp but not sure how I can trap this event.
If the left button is pressed and then the right button is pressed with a delta delay, that is OK. When the user releases the right button / left button and if this is followed up by release of other button within a defined epsilon time then such an event should be raised.
There is no such event in WinAPI, but you may track it yourself. wParam of all button down/up messages contains information of the state of all buttons at the time of event:
MK_LBUTTON 0x0001 The left mouse button is down.
MK_MBUTTON 0x0010 The middle mouse button is down.
MK_RBUTTON 0x0002 The right mouse button is down.
Thus, you need to keep the track of changes and define a threshold that will filter out all events that you like to consider as a "simultaneous click/release"
You will need to write your own method of handling this. Record when the first button was clicked, when the other button is clicked see if the first button is still down and if the delay is less than whatever delta you've supplied.
If GetAsyncKey(0x01) && GetAsyncKey(0x02){
DoEvent();
}