Mouse click detection

Just starting out? Need help? Post your questions and find answers here.
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

Mouse click detection

Post by TimmyTom »

I need to detect mouse click, and then continuously (unlike PB's screwed up Event system that gives me ONE event, no matter how long you hold down or how hard you hit your mouse with a brick (which i started doing after seeing how screwed up PB's mouse event handling is))

I also do not want to use a callback.

So, i need something like GetAsyncKeyState but then for the mouse buttons

I cannot phatom the amount of thinking (or rather, no-thinking) that went into giving us WindowMouseX and WindowMouseY but not a MouseButton function.

Any ideas?

Tim
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Post by Randy Walker »

Got Problems with documentation or any other gripes? Click around here some and find out how others feel about PureBasic. Then read here consider how little you paid and don't be an ingrate.

viewtopic.php?t=11740&highlight=pay+updates

You are new here and I've only been here (using PureBasic) for a few months. You need to READ to understand why things are as they are. I was also very confused by it all. Developement efforts seem more focused on the program rather than the documentation but you will find (IF YOU LOOK) that PureBasic is fully competent to do virtually anything you want to do under the Windows platform. I have no experience yet with the others but I expect they too grant near complete if not complete access to them as well. As far as documentation, your specific question has already been answered more than once here on this forum... try the SEARCH feature and then R-E-A-D !!

Or if you'd like to post a civil question...

BTW... Welcome to PureBasic :)

[EDIT] I thought you were new here by your question and no member rating under your name. Now I see "Joined: 18 Aug 2003" so maybe not a newbie.
Last edited by Randy Walker on Wed Jan 12, 2005 7:20 am, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Mouse click detection

Post by PB »

> unlike PB's screwed up Event system that gives me ONE event

Insulting PureBasic isn't the way to get help.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

Post by TimmyTom »

So, i am gathering there is no easy way to do this. A simple MouseDown() function ala Blitz isn't possible in PureBasic without going the difficult way. Pretty useless if you ask me. PureBasic is a nice language for simple apps, but that seems to be the extend of it.. pity.

Mind you, i wouldn't be using it if i hated it, i truly do like PureBasic, but to get anything done one seems to be forced to do massive workarounds for a lot of stuff.

Tim
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

What version of Blitz are you comparing to? You didn't say if you are using a DirectX screen or a Window.

Anyway, can something like this not get you started??

Code: Select all

If OpenWindow(0,0,0,400,300,#PB_Window_SystemMenu,"")
  Repeat
    eventid=WindowEvent()
    If eventid=#PB_Event_CloseWindow
      quit=1
    EndIf
      
    If eventid=#WM_LBUTTONDOWN
      buttondown=1
    EndIf  
    If eventid=#WM_LBUTTONUP
      buttondown=0
    EndIf
    
    If buttondown
      Debug "Button Down"
    EndIf
    
    Delay(1)
  Until quit
EndIf
Image Image
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

Post by TimmyTom »

Yeah, i am doing something like that now Paul, seems to be the easiest solution, even if i would rather not deal with window events at all.

I am actually using a windowed OpenGL screen in this case.

Tim
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

You can use 'GetAsyncKeyState()' to detect the state of a mouse button also... You should read up a bit on win API..
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

Post by TimmyTom »

Really? hmm, my win32 api reference doesn't mention one word about that.. but, worthy of testing :)

Thanx :)

Tim
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

WIN API wrote: The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, which may mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling

GetSystemMetrics(SM_SWAPBUTTON)


which returns TRUE if the mouse buttons have been swapped.
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

Post by TimmyTom »

Yeah, works great! thanks for that.. guess i'll need to get another Win32 API reference, as this one stinks :)

Tim
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Code: Select all

If OpenWindow(0,0,0,400,300,#PB_Window_SystemMenu,"")
  Repeat

    If GetAsyncKeyState_(#VK_LBUTTON)
      Debug "Mouse Click"
    EndIf

    eventid=WindowEvent()
    If eventid=#PB_Event_CloseWindow
      quit=1
    EndIf
   
    Delay(1)
  Until quit
EndIf 
Image Image
Post Reply