I wanted to connect a computer mouse to a microcontroller for some projects I am experimenting with. So, naturally, I did a web search to find an existing mouse library. I found a lot of code snippets, but only one really well written library, especially in its timeout handling. That one is by Dany Rosseel, and I found it on the mikroElektronika projects page. Dany's code is written in mikroPascal for PIC, so I translated it to mikroC for PIC and, with Dany's permission, sent my code to mikroElektronika to post on their projects page. The code is pretty straightforward, and should be easy to convert to another dialect of C or C++. Have fun with it - I know I am!
mikroElektronika got rid of their projects page, so you can download my C code here.