Announcement

Collapse
No announcement yet.

Clearing mouse events

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Clearing mouse events

    Anyone know how to clear the buffer of pending mouse events in a graphics window?

    I'm finding GRAPHIC WINDOW CLICK very useful for making an easy graphics console, but incautious mouse clicks can result in the program getting ahead of itself.

    Code structure is something like...

    DO

    GRAPHIC WINDOW CLICK hWin TO clickval,x,y

    IF clickval THEN
    ... various actions based on location of x,y in the graphics window
    END IF

    clickval=0

    GRAPHIC INPUT FLUSH

    SLEEP 100

    LOOP

    The GRAPHIC INPUT FLUSH statement appears to clear keyboard events, but not mouse clicks, so extra clicking whilst executing statements within the IF block causes an immediate jump back into the block as soon as those statements are done. Presumably this is because the click event is stored, so that even after clickval is reset to zero, it immediately becomes TRUE again on the next cycle of the loop.

    Any (easy!?) way to solve this?

    Any help much appreciated...

  • #2
    This is related: http://www.powerbasic.com/support/pb...ad.php?t=38829
    How long is an idea? Write it down.

    Comment


    • #3
      The GRAPHIC INPUT FLUSH statement appears to clear keyboard events, but not mouse clicks
      I don't "do" GRAPHIC windows, but for those who do, a New Feature Suggestion, "Please provide a facility to flush queued mouse clicks similar to the way GRAPHIC INPUT FLUSH flushes keystrokes" might be in order.... send those NFSs to [email protected]

      You might go as far as suggesting a useful and backward compatible syntax:
      Code:
       GRAPHIC INPUT FLUSH  [,MOUSE]
      If the optional key word MOUSE is provided, mouse clicks are flushed, otherwise only keystrokes are flushed.

      MCM
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Mike - thanks. That's useful to see, though I don't think I can use it in my current CC application. I think my answer is to change the routine so that the next click will always be meaningful. At the moment I have GRAPHIC INPUT statements waiting for the Enter key to be pressed, which means that extra mouse clicks (or at least the last of any extra clicks) wait to be dealt with until GRAPHIC INPUT is done. If I use GRAPHIC INKEY$ to accumulate input one character at a time then no Enter is necessary and I can any mouse clicks to terminate an input loop. This would make the program responses more intuitive for the user anyway (though this scarcely matters, as I'll be the main user...).

        Comment


        • #5
          MCM - consider it sent...

          Comment


          • #6
            I would not normally suggest anything like this, but since this seems to be serious oversight in the design of the GRAPHIC INPUT FLUSH statement (hey, guys, mouse clicks are input, too!) ............

            You actually could flush these yourself, by inserting a PeekMessage (with remove option) loop in your code, filtering for only mouse messages so you don't lose anything important.

            This would be totally unsupported, but may well work. If you are not quite up to writing this yourself, don't worry, no doubt someone will write it for you and post it.

            MCM
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Since (graphic)INKEY$ is supposed to trap both keyboard and mouse events, seems reasonable that:

              do until (graphic)inkey$ = ""
              loop

              or something like that would work.

              Or do I need to RTFM again?
              There are no atheists in a fox hole or the morning of a math test.
              If my flag offends you, I'll help you pack.

              Comment


              • #8
                Code:
                do until (graphic)inkey$ = ""
                loop
                :doh:

                I told you I don't 'do' GRAPHIC ANYTHING....
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Mel - thanks anyway, but the problem isn't one of trapping the mouse events. That's already happening with GRAPHIC WINDOW CLICK. The problem is one of getting rid of unwanted clicks so that they're not hanging around waiting to be trapped.

                  Comment


                  • #10
                    "INPUT FLUSH" is supposed to clear keyboard and mouse buffers.
                    I just read the docs and GRAPHIC INKEY$ etc only deal with the keyboard.
                    I do not use GRAPHICS with consoles.
                    Have you tried "INPUT FLUSH" instead of "GRAPHIC INPUT FLUSH?"
                    Last edited by Mike Doty; 25 Mar 2009, 12:25 PM.
                    How long is an idea? Write it down.

                    Comment


                    • #11
                      Mike - yes, tried that: no luck... I think that just works with the console and leaves the graphics window alone.

                      Comment


                      • #12
                        How about this?
                        Multiple mouse buffers?
                        Code:
                        SUB FlushMouse
                          LOCAL x AS LONG
                          FOR x = 1 TO 4
                            INPUT FLUSH
                            SLEEP 10
                          NEXT
                        END SUB
                        I had a similar problem with GUI apps.
                        How long is an idea? Write it down.

                        Comment


                        • #13
                          Mike - thanks. FlushMouse didn't work, but it made me think of something that did... I simply inserted another GRAPHIC WINDOW CLICK to deal with the stored mouse events...

                          DO
                          GRAPHIC WINDOW CLICK hWin to clickval,x,y ' deals with wanted clicks

                          IF clickval THEN

                          ... do useful things

                          GRAPHIC WINDOW CLICK hWin to clickval2,x,y ' deals with unwanted clicks
                          IF clickval2 THEN clickval=0

                          END IF
                          SLEEP 100
                          LOOP
                          This seems to do the trick, as just one spare click seems to be stored.

                          Comment


                          • #14
                            Michael:

                            DO

                            DO UNTIL CLICKVAL=0

                            GRAPHIC WINDOW CLICK hWin to clickval,x,y

                            LOOP

                            GRAPHIC WINDOW CLICK hWin to clickval,x,y ' deals with wanted clicks

                            IF clickval THEN

                            ... do useful things


                            END IF

                            SLEEP 100

                            LOOP

                            Comment


                            • #15
                              Manuel - thanks, that does the trick more neatly.

                              Comment

                              Working...
                              X