Here is a quick and dirty (and very incomplete) keyboard. There are two kinds of keys -- standard and special. And Special can be literal (like space is " ") or not, like Return is newline. You'd have to think through cases like Shift, Alt, Ctrl... But it is a start.
keyboard.capx
All I'm doing is appending text. For your application you'll have to figure out what the key codes are and send them as appropriate, and that's the hard part, I guess.