An alternative approach (if your "keyboard" doesn't have many keys - many devices pretend to be keyboards) is to apply a keymapping to each keyboard specifically and ensure that keys are distinguished.
This is outlined here: http://superuser.com/questions/760602/how-to-remap-keys-under-linux-for-a-specific-keyboard-onlyhttps://superuser.com/questions/760602/how-to-remap-keys-under-linux-for-a-specific-keyboard-only. The main point being the setxkbmap takes a device argument.
If you are using the raw input approach the lsinput will find your raw device for you.