Page 1 of 1
LeftMouseButtonUP() windows
Posted: Thu Oct 02, 2008 5:00 pm
by Rook Zimbabwe
OK I have been beating my head against a wall for a simple API way to check for LEFT mouse button UP... RIGHT mouse button UP etc.
I didn't want to add a huge library of really well written procedures to my program.
I have just finished this and about 2 weeks reading and rereading the API references on the MOUSE... (I am now cross-eyed and devoutly insane BTW!)
My solution was simple.
Code: Select all
If MouseButton(#PB_MouseButton_Left)
LBUTSTATE = GetAsyncKeyState_(#VK_LBUTTON) ; this = 32768 if PRESSED
; Debug "MOUSE STATE: "+Str(GetAsyncKeyState_(#VK_LBUTTON)) ; uncomment to see
If LBUTSTATE = -32767 ; LEFT mouse button UP = -32767 : )
; INSERT YOUR CODE HERE
EndIf
; LBUTSTATE = 0 ; not needed as I found out
EndIf
All in all it is pretty simple
Posted: Thu Oct 02, 2008 8:17 pm
by eddy
it could be usefull for my drag panelgadget tabs snippet

Posted: Thu Oct 02, 2008 8:42 pm
by Kaeru Gaman
All in all it is pretty simple
... and almost wrong.
when you use PB's "MouseButton" Function, you should not use additionally GetAsyncKeystate.
the way you use it causes a problem:
you only check for UP via API when you previously had a DOWN by PB's MouseButton.
if you want to use API:
check for Focus additionally, then you can use it on every Window, no screen needed.
(and you should be aware that Get
AsyncKeystate always checks for physical buttons, a lefthander mouse will not be rocognized.)
If you want to use PB's MouseLib (what I would prefer for a Fullscreen Game) you can flag it with 4 values:
Code: Select all
#MButtonFree = 0
#MButtonDown = 1
#MButtonHold = 2
#MButtonUp = 4
Define LeftMouseButtonState.l
;...
If MouseButton( #PB_MouseButton_Left )
If LeftMouseButtonState = #MButtonDown Or LeftMouseButtonState = #MButtonHold
LeftMouseButtonState = #MButtonHold
Else
LeftMouseButtonState = #MButtonDown
EndIf
Else
If LeftMouseButtonState = #MButtonDown Or LeftMouseButtonState = #MButtonHold
LeftMouseButtonState = #MButtonUp
Else
LeftMouseButtonState = #MButtonFree
EndIf
EndIf
Posted: Fri Oct 03, 2008 4:01 am
by Rook Zimbabwe
Kaeru... your IF/THEN logic loop has me almost cross eyed again... I think I see what you are getting at, but that is a bigger decision tree than mine...
I simply want to check keystate if the LEFT button is pressed... otherwise the button continues firing which can be annoying in some instances...
Which is WHY we need this to be built IN to PB 4.3! (HINT Fred! Timmo! Guys!?)
... and almost wrong.
Yep, but it werks!

Posted: Fri Oct 03, 2008 7:41 am
by blueznl
Under Windows you can detect mouse button events, there's one for up, for down, for each button...
But yes, a function that returns the current state of the mouse button would be nice and same some thinking

Posted: Fri Oct 03, 2008 10:05 am
by Trond
MouseButton() uses DirectX(), its not for normal programs.
Code: Select all
OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
Repeat
Select WaitWindowEvent()
Case #WM_LBUTTONUP
Debug "Up!"
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
Posted: Fri Oct 03, 2008 11:05 am
by Kaeru Gaman
but that is a bigger decision tree than mine...
the SIZE of a decision tree does not matter.
if it is straightforward, if will evaluate fast, this is what counts.
sure you can use the Keystate API-functions, but then better use them alone and not mixed up.
and the return values of GetAsyncKeystate are not THAT simple:
the first click is -32767 in normal cases, -32768 if the click sets focus on the window, 1 if you click on the exit-button, etc.
and 32768 id HOLDING the button down, not the first click.
Posted: Fri Oct 03, 2008 3:23 pm
by Rook Zimbabwe
Kaeru: but does the number of operations in a decision tree make a difference?
Maybe not since it is usually a simple 1 or 0 decision...
Hmmm...
Your code is more accurate!
BUT:
Why wasn't there mention of this:
Case #WM_LBUTTONUP before?
I just need to get the coordinates of the mouse when the button is released! That would avoid the 1000 times a second update from my mouse to the OS!

Posted: Fri Oct 03, 2008 4:45 pm
by Kaeru Gaman
Rook Zimbabwe wrote:Why wasn't there mention of this: Case #WM_LBUTTONUP before?
as I see it, there will be NO eventhandling at all in a fullscreen-game, so it's impossible to use #WM_LBUTTONUP.
on the other Hand, on a "normal" Window there is no DX, no support for the MouseLib, so then the solution I posted will not work. (wich is why Trond posted this)
only on a windowedscreen you could access both, but then again you have to be careful when and how to mix them together.
Posted: Fri Oct 03, 2008 6:03 pm
by tinman
If you intend to use the #WM_LBUTTONUP method then you can get the co-ordinates like this:
Code: Select all
Case #WM_LBUTTONUP
pos.l = GetMessagePos_()
x.l = pos & $FFFF
y.l = (pos >> 16) & $FFFF
Debug Str(x) + " " + Str(y)
Posted: Fri Oct 03, 2008 9:00 pm
by Trond
With position:
Code: Select all
OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
Repeat
Select WaitWindowEvent()
Case #WM_LBUTTONUP
Debug "Up at "
Debug EventlParam() >> 16
Debug EventlParam() << 16 >> 16
Debug "---"
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
Posted: Sat Oct 04, 2008 5:59 am
by Rook Zimbabwe
Now here is the fun part... I have a windowed screen and controls outside the window...
But all of this is very interesting... maybe have to whip up a small PBI for both functions!
If one of you gurus of Mouse Coolness fells like chunking that together I won't stop you!
As an idea, you could add in all the other missing windows mouse features, including change the cursor and wait cursor etc.
That way I coud be lazy and sit on my butt and not do anything!
