i'm building and application that listens for keyboard input (when the program is in the background) and then does various tasks when a certain key is pressed.
for instance i press f5 and a greeting message is typed out.
so its kind of like a macro program to automate some tasks.
i know how to simulate keyboard presses, i just don't know how to listen for keyboard input when the program is not in focus.
FWIW I think what you are trying to do is a really, really bad idea. For example, I use F5 all the time to maximize/minimize the edit window in my Delphi 5 IDE. If something hooks that on a system level, that something must die.
This is because when you hook things you are breaking the UI abstraction that the user expects: pressing keys should have an application-defined meaning; Other applications should not interfere.
There are few exceptions, like Ctrl-Alt-Delete that MSGINA hooks so that rogue applications can be overridden by the system, but in general such things are considered bad karma.
Although, I suppose if you are careful, you might provide some useful features in a specific problem subdomain...