I always thought that somebody has already created software to do so. Example, you chose which HID device sends commands to which process. Though my knowledge of OSes is very narrow, I may misjudge.
http://www.hidmacros.eu/whatisit.php - Would this help ?
Connect With Us