I am not quite sure what you want to do with idleness or what you mean by idle but
user32.dll
exports
GetLastInputInfo[
^] which you can check timely fashion to decide whether PC is idle or not. For instance, "2 minutes past since last user input, so I assume user is away from keyboard and this code will do blah blah".