From Inspired-Lua Wiki
Revision as of 13:25, 17 June 2012 by Adriweb (talk | contribs) (Link)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The event on.grabDown is used to handle grabbing motions (cursor press & hold).

This routine is called in these situations:

  • When the user presses and holds the Select key on a device
  • When the user presses Ctrl + Select on a device
  • When the user presses the middle mouse button over an active card on the desktop

The passed coordinated, x and y, are always 0 and 0. The grabDown and grabUp events prevent the generation of a mouseUp event in all cases.

They will be preceded by a on.mouseDown event when generated by pressing and holding the Select key on a device.


Below is an example of a program that handles the grabbing motion to move an object :

function Ball:move(x,y)
     self.x = x
     self.y = y

function on.grabDown(x,y)
     isGrabbing = not isGrabbing -- makes the variable switch from true to false and vice versa

function on.mouseMove(x,y)
     if isGrabbing and (trackedBall and trackedBall.isActive) then  -- assuming trackedBall is defined etc. 

You can see the whole lua example about Ball generation and movements here : Balls Example (Class + Events Handling)

See Also