WindowMouseButton()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

WindowMouseButton()

Post 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.

8)

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
???
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post 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 ?!?
BriceManuel
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Nov 29, 2007 8:23 am

Post 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:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

@Berikco:
Excellent idea, and of particular use to someone making a crossplatform visual designer. Add my voice to the crowd!
BERESHEIT
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Search the forums for a solution...

http://www.purebasic.fr/english/viewtop ... ousebutton
bye,
Daniel
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post 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 ?......
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post 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.
bye,
Daniel
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post 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
BriceManuel
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Nov 29, 2007 8:23 am

Post by BriceManuel »

I gotta agree with Berikco on this one :wink:
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post 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).
bye,
Daniel
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post 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 :(
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Actually MouseDrag() and MouseButtonUp() would be good ideas as well! 8)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Rook Zimbabwe wrote:Actually MouseDrag() and MouseButtonUp() would be good ideas as well! 8)
What exactly would they do ?
quidquid Latine dictum sit altum videtur
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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...
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

I'd settle for just a simple mousebutton() but I'm not that demanding... today.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply