A way to know if the mousebutton was pressed or released.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

A way to know if the mousebutton was pressed or released.

Post by Joakim Christiansen »

A way to know if the mousebutton was pressed or released.
I had to make my own little procedure to do this.
The command MouseButton() only return if it's down or not.
I like logic, hence I dislike humans but love computers.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Also, a command like MouseButton() that works even if the mouse is NOT captured... It's very annoying to need a mouse to be captured just to tell if its been clicked.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

I also want to know it the keyborad button was pressed... :twisted:
We should have a KeyboardPressed()
I like logic, hence I dislike humans but love computers.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Isn't KeyboardReleased() enough ?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Maybe it is, sorry then...

Edit:
But it would make the command set more complete.
I think it should be something like this:

Code: Select all

Result = MouseDown(ButtonNumber)
Result = MousePressed(ButtonNumber)
Result = MouseReleased(ButtonNumber)
Result = KeyboardDown(KeyID)
Result = KeyboardPressed(KeyID)
Result = KeyboardReleased(KeyID)
Last edited by Joakim Christiansen on Wed Aug 24, 2005 6:17 pm, edited 2 times in total.
I like logic, hence I dislike humans but love computers.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Yes it is, however my point about mousecommands not working when the mouse is released should be considered =)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Actually we should be able to know if any button is released or pressed so we don't have to create our own stupid procedures to find it out.

It would make the command set more complete and I recommend functions like this :P:

Code: Select all

If KeyboardKey(#PB_Key_Left,#PB_Button_Pressed)
  ;do something
EndIf
If MouseButton(#PB_MouseButton_Left,#PB_Button_Released)
  ;do something
EndIf

Code: Select all

#PB_Button_Down
#PB_Button_Pressed
#PB_Button_Released
;or maybe shorter syntax like #Down, #Pressed, #Released... whatever
It should be optional and the default one should be #PB_Button_Down

Am I complaining now? :lol:
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

first of all, some native rmb support would be nice, as well as mousewheel support!

anyway, i currently use:

Code: Select all

Procedure.l x_leftmousebutton()                                      ; return current state of left mousebutton
  ;
  ; retval: #True  - mouse button down
  ;         #False - mouse button up
  ;
  ; note: does not use events!
  ;
  If GetSystemMetrics_(#SM_SWAPBUTTON) = 0
    ProcedureReturn x_bool(GetAsyncKeyState_(#VK_LBUTTON))
  Else
    ProcedureReturn x_bool(GetAsyncKeyState_(#VK_RBUTTON))
  EndIf
EndProcedure

Procedure.l x_rightmousebutton()                                     ; return current state of right mousebutton
  ;
  ; note: does not use events!
  ;
  If GetSystemMetrics_(#SM_SWAPBUTTON) = 0
    ProcedureReturn x_bool(GetAsyncKeyState_(#VK_RBUTTON))
  Else
    ProcedureReturn x_bool(GetAsyncKeyState_(#VK_LBUTTON))
  EndIf
EndProcedure

Procedure.l x_mousewheel(mode.l)                                     ; returns number of lines up / down upon using the scrollwheel after a #WM_MOUSEWHEEL event
  ;
  ; *** returns number of lines up / down upon using the scrollwheel after a #WM_MOUSEWHEEL event
  ;
  ; in:     mode.l = 0   - one line per message, return -1 for up, +1 for down
  ;                = 1   - use windows setting for calculating number of lines, from -n to +n
  ; retval: <0          - up
  ;         >0          - down
  ;
  If mode = 0
    d = x_sgn( EventwParam() >> 16 )
  Else
    ;
    ; #SPI_GETWHEELSCROLLLINES = 104
    ;
    d = 0
    SystemParametersInfo_(104,0,@d,0)
    d = (EventwParam() >> 16)*d/120
    ;
  EndIf
  ProcedureReturn d
EndProcedure
( 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