|
-
July 30th, 2009, 03:47 AM
#1
GetAsyncKeyState Help
Ok so i making a console program that uses lots of userinput while its running.
The problem is i made sample test code to see if it works and this is the problem. If i press the Shift key it displays my message like 500+ times just in one push of the key. how do i make it so when i push it, it will display the message once each time i push it. Also how would i make code that if they press F11 it enables the program but if they press F11 again it disables program
Code:
if (GetAsyncKeyState(VK_SHIFT))
{
cout << "hi";
-
July 30th, 2009, 05:02 PM
#2
Re: GetAsyncKeyState Help
well when you do this
Code:
if (GetAsyncKeyState(VK_SHIFT))
{
cout << "hi";
you could try adding a pause funtion in there
Code:
if (GetAsyncKeyState(VK_SHIFT))
{
cout << "hi";
system("pause");
}
but im guessing you don't want to do that you want one press, one message so try something like
Code:
if (GetAsyncKeyState(VK_SHIFT))
{
cout << "hi";
_sleep(70);
}
this would make it to where you would have time to let go of the button for it to display only one because it would wait before continuing.
this didn't work in one of my programs for unknown reasons since i didn't get any errors when compiling and when i tried your code it didn't work either. so this is just what i think should work. :P
if it doesn't im sorry because i am also a beginner but still want to help.
-
July 30th, 2009, 05:09 PM
#3
Re: GetAsyncKeyState Help
You say you're making a console application, yet GetAsyncKeystate is a "windows" function - while it can be called, and it can work, it does what it says - gets the state of the keyboard asynchronously - that is, without respect to the number of times a key is pressed.
Look at the sample for kbhit (deprecated _kbhit), check the compatibility notes, and consider it in concert with getch. There are several alternatives.
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
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
|