SDL is another option, but I don't think it will capture key events when the window isn't even focused. Likely because the OS doesn't even pass the key events to the app when it isn't focused, so it has no way to see them.
You'll probably have to hook into the OS (in an OS-specific way) at a way lower level (requiring root/admin privileges). For linux for example, you can have a look at how keyd works to capture (and modify) keyboard events (in C, should be translatable to nim): https://github.com/rvaiya/keyd
ps. You're basically wanting to write a keylogger, which is generally considered malware, so a lot of people might not want to help you do that.
Exactly!