Simply put...
mousex< viewport left...mouse set x to viewport left
mousex> viewport right...mouse set x to viewport right
mouse y<viewport top...mouse set y to viewport top
mouse y > viewport bottom... mouse set Y to viewport bottom...
You may not need all these...
this can get more complex depends on your needs and any layers or scrolling you have going on