GetAsyncKetState in windows service is not working? Help

Hello Everybody, When i use GetAsyncKeyState in a App Console, it's not problem, but when i added it to a windows service, it's not working!
this is my code, i want to print "i'm running" to a file when any keyboard pressed. but.... :(

Please help me!
i'm Vietnamese, sorry because i'm not good at English.

while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
{
short character;
for(character=8;character<=222;character++)
{
if(GetAsyncKeyState(character) == -32767)
{
std::ofstream outfile("D:\\hook.txt");
outfile << "i'm running" <<std::endl;
}
}
}
help me ! please!
:(
Topic archived. No new replies allowed.