GetAsyncKeyState

Posts 1–5 of 5 · Page 1 of 1
GetAsyncKeyState
ok so here is my code, (not a keylogger).


[php]#include <Windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CmdShow, int CmdLine)
{


MessageBox(NULL, TEXT("SUP"), TEXT("SUP"), NULL);


if(GetAsyncKeyState(int (VK_NUMPAD9)) & 0)
{
MessageBox(NULL, TEXT("YES"), TEXT("SKD"), NULL);
return 0;
}

}[/php]
the problem is that after the user presses ok on the first message box the program shuts down, it doesn't wait until you press 9 on the num pad.
use a loop

Code:
#include <Windows.h> 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CmdShow, int CmdLine) 
{ 
     
     
    MessageBox(NULL, TEXT("SUP"), TEXT("SUP"), NULL); 
     
 while (true)
{
      if(GetAsyncKeyState(int (VK_NUMPAD9)) & 0) 
    { 
        MessageBox(NULL, TEXT("YES"), TEXT("SKD"), NULL); 
                         return 0; 
    } 
}
}
this way, the code will wait untill you press numpad9, shows messagebox and will return from main (exit the program).

a better way:
while(!(GetAsyncKeyState(int (VK_NUMPAD9)) & 0)); // will till the key is pressed
MessageBox(NULL, TEXT("YES"), TEXT("SKD"), NULL); // after the key is pressed the messagebox will appear
return 0; //exit the program
You're checking if the key is pressed IMMEDIATELY after the user presses OKAY. Otherwise, you skip the code in the braces.

use logic. The above code fixes it for you.
thanks guys, i tried ur code but it goes straight to the messagebox
Locked due to stupidity, try out stuff yourself and THINK >.>
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?