some doubts about PeekMessage
-
I want to do some test about keyboard loging without using hook api. in the following codz, i hope when i press Esc key, the prog will com to an end. but it seems PeekMessage() will never work, always failed. How could it be? Thanks a lot. #include "windows.h" #include "stdio.h" void main() { MSG msg; char buffer[10]; int i, ch; while(true) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE)) { if( msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) break; //Esc pressed, then quit printf( "Enter a line: " ); /* Read in single line from "stdin": */ for( i = 0; i < 9; i++ ) { ch = getchar(); if(ch != '\n') buffer[i] = (char)ch; } /* Terminate string with null character: */ buffer[9] = '\0'; printf( "%s\n", buffer); *buffer=NULL; } else printf("peekmessage failed...\n"); Sleep(3000); //ensure there is enough time for keyboard operations } }
-
I want to do some test about keyboard loging without using hook api. in the following codz, i hope when i press Esc key, the prog will com to an end. but it seems PeekMessage() will never work, always failed. How could it be? Thanks a lot. #include "windows.h" #include "stdio.h" void main() { MSG msg; char buffer[10]; int i, ch; while(true) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE)) { if( msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) break; //Esc pressed, then quit printf( "Enter a line: " ); /* Read in single line from "stdin": */ for( i = 0; i < 9; i++ ) { ch = getchar(); if(ch != '\n') buffer[i] = (char)ch; } /* Terminate string with null character: */ buffer[9] = '\0'; printf( "%s\n", buffer); *buffer=NULL; } else printf("peekmessage failed...\n"); Sleep(3000); //ensure there is enough time for keyboard operations } }