hi srig,
have a look to this one
http://www.melabs.com/resources/samples/x1/pbp/keyx.bas

that's a start.