http://bur.st/~sacha/
This is a basic example of what you need. I did this with a friend.
Just replace the code with with the correct key-codes, which the link above should probably teach you about, and change it a bit so that the function will produce only key-combinations accordingly.
Glad to potensually help,
Shaffer.