Page 1 of 2
WindowMouseButton()
Posted: Thu Dec 06, 2007 11:47 pm
by Rook Zimbabwe
I love that we can alrady get WindowMouseX() and WindowMouseY() but I think it would be good to be able to get
WindowMouseButton() to see which button was last pressed
and possibly
WindowMouseReleased() to check which button was last released by the user.
These would be good features!
If not... how would I implement this:
Code: Select all
FUNCTION: AX = 6h
Description: Gets the button release information.
Call With : BX = Button to Query
0 = Left Button
1 = Right Button
2 = Center Button
Returns : AX = Button Status(1 if pressed)
Bit 0 = Left Button
Bit 1 = Right Button
Bit 2 = Center Button
BX = Button Release counter
CX = Horizontal Coordinate of last button release
DX = Vertical Coordinate of last button release
???
Posted: Fri Dec 07, 2007 5:41 pm
by Berikco
And extra events
#PB_Event_MouseMove
#PB_Event_RButtonDown
#PB_Event_LButtonDown
#PB_Event_RButtonUp
#PB_Event_LButtonUp
Requested in 2003 and promised to be added
I don't understand why there are #PB_Event_MoveWindow and such, but no mouse ?!?
Posted: Fri Dec 07, 2007 11:19 pm
by BriceManuel
Berikco wrote:And extra events
#PB_Event_MouseMove
#PB_Event_RButtonDown
#PB_Event_LButtonDown
#PB_Event_RButtonUp
#PB_Event_LButtonUp
Requested in 2003 and promised to be added
I don't understand why there are #PB_Event_MoveWindow and such, but no mouse ?!?
Why would you need mouse commands in Windows? Just write console programs and all will be fine :roll:
Posted: Fri Dec 07, 2007 11:36 pm
by netmaestro
@Berikco:
Excellent idea, and of particular use to someone making a crossplatform visual designer. Add my voice to the crowd!
Posted: Sat Dec 08, 2007 9:54 am
by DarkDragon
Posted: Sat Dec 08, 2007 10:36 am
by Berikco
It's not a solution to always have to use API for basic things like the mouse.
it's not a very new input device, like it was invented only last year.
So why is it forgotten ?......
Posted: Sat Dec 08, 2007 10:48 am
by DarkDragon
Berikco wrote:It's not a solution to always have to use API for basic things like the mouse.
The default-library-set of purebasic also uses API. So what's the problem with using it? It's nearly the same way the library will do it. And my procedure has Windows and Linux support.
Posted: Sat Dec 08, 2007 11:05 am
by Berikco
Your is not a SOLUTION
It's a nice workaround for something that should be in PureBasic.
btw, this is the forum for feature requests, not for workaround requests
What looks best for a new user??
This:
Code: Select all
;-ExampleCode:
OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu, "Test")
hWnd = WindowID()
If hWnd <> 0
CreateGadgetList(WindowID())
TextGadget(0, 10, 10, 280, 20, "Status")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_LButtonDown
SetGadgetText(0, "Left MouseButton pressed" )
Case #PB_Event_RButtonDown
SetGadgetText(0, "Right MouseButton pressed" )
Case #PB_Event_MButtonDown
SetGadgetText(0, "Middle MouseButton pressed")
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
End
Or this
Code: Select all
Procedure WindowMouseButton(Wnd, ButtonNr)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
;Linux Version
Protected gdkWnd.l, x.l, y.l, mask.l
If Wnd
*Window.GTKWindow = Wnd
gdkWnd = *Window\bin\child\window
gdk_window_get_pointer_(gdkWnd, @x, @y, @mask)
Select ButtonNr
Case 0
If (mask & #GDK_BUTTON1_MASK)
ProcedureReturn 1
EndIf
Case 1
If (mask & #GDK_BUTTON3_MASK)
ProcedureReturn 1
EndIf
Case 2
If (mask & #GDK_BUTTON2_MASK)
ProcedureReturn 1
EndIf
EndSelect
EndIf
CompilerElse
;Windows Version
If Wnd And GetForegroundWindow_() = Wnd
Select ButtonNr
Case 0
If GetAsyncKeyState_(#VK_LBUTTON) > 0
ProcedureReturn 1
EndIf
Case 1
If GetAsyncKeyState_(#VK_RBUTTON) > 0
ProcedureReturn 1
EndIf
Case 2
If GetAsyncKeyState_(#VK_MBUTTON) > 0
ProcedureReturn 1
EndIf
EndSelect
EndIf
CompilerEndIf
ProcedureReturn 0
EndProcedure
;-ExampleCode:
OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu, "Test")
hWnd = WindowID()
If hWnd <> 0
CreateGadgetList(WindowID())
TextGadget(0, 10, 10, 280, 20, "Status")
Repeat
Event = WindowEvent()
If WindowMouseButton(hWnd, 0)
SetGadgetText(0, "Left MouseButton pressed" )
ElseIf WindowMouseButton(hWnd, 1)
SetGadgetText(0, "Right MouseButton pressed" )
ElseIf WindowMouseButton(hWnd, 2)
SetGadgetText(0, "Middle MouseButton pressed")
EndIf
Delay(15)
Until Event = #PB_Event_CloseWindow
EndIf
End
Posted: Sat Dec 08, 2007 11:49 am
by BriceManuel
I gotta agree with Berikco on this one

Posted: Sat Dec 08, 2007 2:11 pm
by DarkDragon
Berikco wrote:Your is not a SOLUTION
It's a nice workaround for something that should be in PureBasic.
I just wanted to say it's a solution until fred implements it. But Fred won't implement it afaik (He would have done this already at the beginning of PureBasic, when WindowMouseX/Y were invented - You will at least think of it when writing functions for WindowMouseX/Y).
Posted: Sun Dec 09, 2007 11:04 am
by Berikco
DarkDragon wrote:Berikco wrote:Your is not a SOLUTION
It's a nice workaround for something that should be in PureBasic.
I just wanted to say it's a solution until fred implements it. But Fred won't implement it afaik (He would have done this already at the beginning of PureBasic, when WindowMouseX/Y were invented - You will at least think of it when writing functions for WindowMouseX/Y).
Actually, for a cross platform application, it gets a real mess with this.
You also have to track the button up and MouseMove events, trow in global variables for this etc..
Sometimes after a Button down event, i need to look for mouse movement or button up.
It's a real disaster
I give up now, don't want to completely mess up my sources, reverting to a backup now

Posted: Mon Dec 10, 2007 5:50 am
by Rook Zimbabwe
Actually
MouseDrag() and
MouseButtonUp() would be good ideas as well!

Posted: Mon Dec 10, 2007 2:01 pm
by freak
Rook Zimbabwe wrote:Actually
MouseDrag() and
MouseButtonUp() would be good ideas as well!

What exactly would they do ?
Posted: Mon Dec 10, 2007 4:25 pm
by Rook Zimbabwe
MouseDrag() = Checks to see if button is pressed and continues to be pressed whil moving.
MouseButtonUp() checks only for the release of a mouse button. This is better than just checking for mousebutton() since it would only respond once instead of MouseButton() responding many times in the loop as the user mashed his finger on the button at non computer speeds...
Posted: Mon Dec 10, 2007 7:56 pm
by blueznl
I'd settle for just a simple mousebutton() but I'm not that demanding... today.