Detect right mouse click before mouseup event

oncontextmenu is called after mouseup, so erase was getting stuck on. Now right mouse clicks are detected at time of click.