The GetAsyncKeyState call is still inside your WinProc which means it only happens when a message is being processed. When your program is idle nothing will happen.
Also, using goto here is a bad idea for many reasons. #1 is it ignores whatever message you
should be handling and treats it like a WM_PAINT message. #2 is that BeginPaint/EndPaint will only repaint areas that need repainting... so this will not do anything. #3 is that goto is atrocious and should be avoided unless you have a very good reason to use it (read: newbies generally don't -- so to make this easy, let's say you shouldn't be using goto at all)
You seem to still be struggling with the Message Loop and how it actually works. Until you understand it I don't think you should really be trying to do what you're doing, as it is flawed on several levels.
1 2 3 4 5 6
|
//main message loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
|
This right here is your message loop.
GetMessage() is where your program is 99% of the time. It just sits in a quiet loop waiting for Windows to tell the program something happened. Whenever the user moves the mouse over the window... or presses a key, or does something else that interacts with your window... Windows will generate a message and send it to your program.
GetMessage receives that message and fills your 'msg' object with the data about it. GetMessage then returns, allowing the program to continue inside that
while
loop.
Inside the while loop, you call TranslateMessage() which does some additional processing on the message (don't ask me to explain as I don't fully understand it myself)... followed by
DispatchMessage
which sends the message out to your windows message handler.
So ultimately, DispatchMessage is what calls your
WinProc
function.
This means that WinProc is being called only when there is a message to process. If nothing of interest is happening... then WinProc is not running. You can put all the calls to GetAsyncKeyState you want in there... but if you're not receiving any messages, they're not running.
Now that I see what you're doing... I realize you probably do not want GetAsyncKeyState. Rather, you want Windows to notify you (send a message) when the key is pressed. This is normally done through the message system.
When a key is pressed, windows sends a WM_KEYDOWN message... with the key being pressed in the 'wParam' paramter. Likewise, when the key is released, Windows sends WM_KEYUP.
1 2 3 4 5 6 7 8 9 10
|
switch( message )
{
//...
case WM_KEYDOWN:
if( wParam == 'D' ) // 'D' key is pressed
{
// ... do whatever you want here
InvalidateRect( hWnd, NULL ); // force the entire window to repaint
}
break;
|
Lastly... if you are doing this for a game (which I'm guessing by the text "gfx engine" in there), I strongly suggest you consider using a graphic lib like SFML. WinAPI absolutely sucks for that kind of work.