best way to detect an object being shake while touched?

what is the best way to detect if an object is being shaken while touched?

It is just there are a lot blocks in my level editor so I need to make my block tool bar smaller

I was wanting to do something like Mario maker (here is video if you have not seen)

https://www.youtube.com/watch?v=U4BsRchAlkE

Any idea on what the best way to do this is?

Thanks,

Scott

Edit: 

local myRect = display.newRect( display.contentCenterX, display.contentCenterY, 100, 100 ) local howManyShakes = 5 local shakeCount = 0 local shakeTimer local function shakeItUp( ) print("I am dizzy" ) end local function myRectTouch( event ) local self = event.target if event.phase == "began" then self.dir = "left" self.markX = self.x -- store x location of object self.markY = self.y -- store y location of object elseif event.phase == "moved" then local x = (event.x - event.xStart) + self.markX local y = (event.y - event.yStart) + self.markY self.x, self.y = x, y -- move object based on calculations above -- time to shake it up if (self.lastX and self.dir == "left" and event.x \> self.lastX+10 ) then self.dir = "right" shakeCount = shakeCount+1 elseif (self.lastX and self.dir == "right" and event.x \< self.lastX-10 ) then self.dir = "left" shakeCount = shakeCount+1 end local function shakeTimerHandle( ) shakeCount = 0 self.lastX = event.x end if (shakeTimer == nil) then self.lastX = event.x shakeTimer = timer.performWithDelay( 1500, shakeTimerHandle, 0 ) end if (shakeCount \>= howManyShakes) then shakeCount = 0 shakeItUp() end elseif event.phase == "ended" or event.phase == "cancelled" then if (shakeTimer) then timer.cancel( shakeTimer ) shakeTimer = nil end end return true end myRect:addEventListener( "touch", myRectTouch )