It depends heavily on the game but generally it can be done. You need to get the game's process ID and info from the operating system, then you can send it commands as if they came from the device via the message pump system in windows.
Reading from the game is more tricky. Most bots send blindly, knowing where to click on the interface for the repeated task.
A friend of mine coded a little actuator to poke his keyboard instead, this was easier than hacking the game.