Ok, I DuckDuckGoed that for you. See the accepted answer to How to distinguish input from different keyboards?. No library required, apparently.
If you're using Linux, the best way to distinguish between input
devices is to use the Linux Event Interface. After a device's
hardware-specific input is decoded, it's converted to an intermediate