Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - mousebuttwrel() wait for specified mouse button release http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 mousebuttwrel()     Wait for specified mouse button release
------------------------------------------------------------------------------
 Declaration
   mouse.hdr

 Syntax
   proc mousebuttwrel extern
   param value uint uButton

 Arguments
   uButton is a mouse button number. See mouse.hdr for mouse button
   identifier constants.

 Return
   None.

 Description
   This procedure halts program execution until the specified mouse button
   is released.

 Example
   #define EXAMPLE_MOUSE
   #include example.hdr

   #define EVENT_NONE      0
   #define EVENT_MOUSE     40000UI
   #define EVENT_DBLCLICK  40010UI
   
   #define ADDR_TIMER      0x0040006c // BIOS timer address
   #define SPEED_DBLCLICK  5          // mouse double click interval in ticks
   
   vardef static
      ulong        nLastClick := 0       // last mouse click time
      ptr( ulong ) pTimer      := ADDR_TIMER
   enddef
   
   func uint EventProc
   // Key+mouse event handler with double click processing
   vardef
      uint uEvent                        // event identifier
   enddef
   uEvent := EVENT_NONE                  // initialize event identifier
   do while uEvent == EVENT_NONE         // wait until no event
      if iskey() != 0                    // if key pressed
         uEvent := inkey()               // event = keypress
      else
         uEvent := mousebuttval()        // event = mousepress
         if uEvent
            mousebuttwrel( uEvent )      // wait for release
         endif
         if uEvent == MB_LEFT            // left button
            if *pTimer - nLastClick < SPEED_DBLCLICK
               uEvent := EVENT_DBLCLICK  // event is double click
            else                         // if single click
               uEvent += EVENT_MOUSE     // add mouse bias
            endif
            nLastClick := *pTimer        // update click measure
         else
            if uEvent == MB_RIGHT        // right button
               uEvent += EVENT_MOUSE     // add mouse bias
            endif
         endif
      endif
   enddo
   return( uEvent )                      // return event value
   endfunc
   
   proc Test_mousebuttwrel
   vardef
      uint uEvent
   enddef
   if mouseavail()
      clear
      ?? "Press keys and mouse buttons. Finish with a double click"
      @ 2, 0 ?? "Event:"
      mouseon()
      do while .t.
         uEvent := EventProc()
         @ 2, 6 ?? uEvent
         if uEvent == EVENT_DBLCLICK
            ? "Double click detected"
            wait
            exit
         endif
      enddo
   else
      ? "No mouse available"
   endif
   endproc

   proc main
   Test_mousebuttwrel()
   endproc

See Also: mousebuttwpress()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson