Take a look at the Omega input unit. It looks very much like the code you posted. One downside (for you) is that it uses Directinput. Do you have reasons to not use that API?? I integrated it into my engine and it works OK.

When i'm back from switzerland, i send you that unit over MSN if you like.