|
-
Dec 19th, 2002, 04:50 PM
#1
Thread Starter
Fanatic Member
GetAsyncKeyState
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...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Dec 19th, 2002, 11:15 PM
#2
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 20th, 2002, 06:43 AM
#3
Thread Starter
Fanatic Member
If I do like this:
Code:
MessageBox(NULL, "Test", "Test", MB_OK);
if(GetAsyncKeyState(VK_RETURN))
{
MessageBox(NULL, "You've pressed Enter", "Enter", MB_OK);
}
The "You've pressed Enter" messagebox will appear right after the "Test" one, if i press Return to OK the "Test" box...
[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...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Dec 20th, 2002, 09:38 AM
#4
Thread Starter
Fanatic Member
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;
}
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Dec 20th, 2002, 03:23 PM
#5
Hyperactive Member
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;
}
-
Dec 20th, 2002, 04:29 PM
#6
Hyperactive Member
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;
}
I know a lot oF Vb, expert in C++, and i think in assembly.
MSVC++6.NET
vb6
masm
Windowz Xp
I find my self using this a lot in C++
__asm {
}
-
Dec 20th, 2002, 08:46 PM
#7
Hyperactive Member
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
-
Dec 21st, 2002, 10:30 AM
#8
Thread Starter
Fanatic Member
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.
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|