Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WIN32 API to find Mouse Button State

WIN32 API to find Mouse Button State

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorial
7 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    poda
    wrote on last edited by
    #1

    Dear Friends, How to know whether the mouse button is Down even if it moving.The WM_LBUTTONDOWN message is fired only for the first time left button is pressed. But how to know whether it is pressed all the time though it may be moving.

    M N P H 4 Replies Last reply
    0
    • P poda

      Dear Friends, How to know whether the mouse button is Down even if it moving.The WM_LBUTTONDOWN message is fired only for the first time left button is pressed. But how to know whether it is pressed all the time though it may be moving.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Maybe GetAsyncKeyState()[^]. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        Maybe GetAsyncKeyState()[^]. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        Calling GetKeyState may be a better choice as it reflects state of the button when the current message was generated.

        Steve

        M 1 Reply Last reply
        0
        • P poda

          Dear Friends, How to know whether the mouse button is Down even if it moving.The WM_LBUTTONDOWN message is fired only for the first time left button is pressed. But how to know whether it is pressed all the time though it may be moving.

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          poda wrote:

          How to know whether the mouse button is Down even if it moving.

          Add event handler for WM_MOUSEMOVE. If the WPARAM for this event has MK_LBUTTON set then left mouse button is down, or if it has MK_MBUTTON, MK_RBUTTON then the corresponding mouse button is down! If you are using MFC then use void OnMouseMove( UINT nFlags, CPoint point ). nFlags will contain appropriate flags to indicate whether left, middle, right buttons or whether shift key is down. Use bitwise and to find out. E.g.

          if(( nFlag & MK_LBUTTON ) == MK_LBUTTON )
          AfxTrace( "You are dragging the mouse\n" );

          Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

          modified on Friday, April 11, 2008 2:58 AM

          1 Reply Last reply
          0
          • S Stephen Hewitt

            Calling GetKeyState may be a better choice as it reflects state of the button when the current message was generated.

            Steve

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            I'm sure that's what I meant :) Thanks Steve! Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            1 Reply Last reply
            0
            • P poda

              Dear Friends, How to know whether the mouse button is Down even if it moving.The WM_LBUTTONDOWN message is fired only for the first time left button is pressed. But how to know whether it is pressed all the time though it may be moving.

              P Offline
              P Offline
              poda
              wrote on last edited by
              #6

              Thanks for your replies friends. I used like SHORT LButtonDown; LButtonDown=GetKeyState(VK_LBUTTON); if(LButtonDown & 0x8000) { ...code here } It works.Thanks a lot.

              1 Reply Last reply
              0
              • P poda

                Dear Friends, How to know whether the mouse button is Down even if it moving.The WM_LBUTTONDOWN message is fired only for the first time left button is pressed. But how to know whether it is pressed all the time though it may be moving.

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                Im not sure see here[^] and here[^] does any help?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups