How do I flush the GetAsyncKeyState buffer? It's really anoying when my program think that I've pressed Return just because I've selected OK in a messagebox...
Printable View
How do I flush the GetAsyncKeyState buffer? It's really anoying when my program think that I've pressed Return just because I've selected OK in a messagebox...
GetAsyncKeyState retrieves the physical state of your key, unlike GetKeyState you can't do anything about it, are you sure that you're not missing something, the virtual key for the left mouse button is 1 while return is 13
If I do like this:The "You've pressed Enter" messagebox will appear right after the "Test" one, if i press Return to OK the "Test" box...Code:MessageBox(NULL, "Test", "Test", MB_OK);
if(GetAsyncKeyState(VK_RETURN))
{
MessageBox(NULL, "You've pressed Enter", "Enter", MB_OK);
}
[MSDN]
If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState
[/MSDN]
I think that's the problem because I call GetAsyncKeyState in a another loop that gets run before this call...
Try this and you'll see what I mean. Run it once like it is and then you uncomment the MessageBox-line and you'll notice my problem... The second messagebox shouldn't appear "on its own"
Code:#include <iostream>
#include <windows.h>
using namespace std;
void main()
{
bool bRunning = true;
cout << "Press Return" << endl;
//MessageBox(NULL, "Test", "Test", MB_OK);
while(bRunning)
{
if(GetAsyncKeyState(VK_RETURN))
{
MessageBox(NULL, "You've pressed Return", "Return", MB_OK);
bRunning = false;
}
}
return;
}
How about trying this
Code:#include <iostream>
#include <windows.h>
using namespace std;
void main()
{
bool bRunning = true;
cout << "Press Return" << endl;
//MessageBox(NULL, "Test", "Test", MB_OK);
while(bRunning)
{
if(GetAsyncKeyState(VK_RETURN) & 0x8000)
{
MessageBox(NULL, "You've pressed Return", "Return", MB_OK);
bRunning = false;
}
}
return;
}
i use this and it should work...
VB Code:
#include <iostream> #include <windows.h> using namespace std; int regt; void main() { bool bRunning = true; cout << "Press Return" << endl; //MessageBox(NULL, "Test", "Test", MB_OK); while(bRunning) { regt = GetAsyncKeyState(VK_RETURN) if(regt) { MessageBox(NULL, "You've pressed Return", "Return", MB_OK); bRunning = false; } } return; }
GetAsyncKeyState() does not work in a console.
http://www.vbforums.com/showthread.p...tasynckeystate
There is a bug with my attached code when 3 keys are pressed. 2 keys should be okay I think.
http://www.vbforums.com/showthread.p...tasynckeystate
Ok, guys. I must've explained poorly...
Run the code as it is and it DOES work.
Uncomment (i.e. remove the //) the "MessageBox(NULL, "Test", "Test", MB_OK);" line and it doesn't work (like I want it) any more.