How to convert raster and windows coordinate?

I want to determine what the user has clicked by examining the pixel of a mouse click. To read a pixel, I need a raster coordinate but the mouse is using windows coordinate. How do I convert between raster coordinate and windows coordinate?

If I use unProject API (depth=0.9), I will get an approximated raster coordinate from a mouse coordinate(x,y). How do I improve on the accuracy?