Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Arrow key detection with GetAsyncKeyState
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-26-2011, 04:00 PM
Blupig's Avatar
i am a guy ok?? -.-
Ex-Moderator Zombie Visual Basic Programmers
 
Join Date: Nov 2006
Location: Canada
Posts: 5,232
Send a message via MSN to Blupig Send a message via Skype™ to Blupig
MushyMuncher
Image Arrow key detection with GetAsyncKeyState

Hello, here's my code:

Code:
#include <iostream>
#include <Windows.h>
using namespace std;

int main(){

	short key;

	do {

		key = GetAsyncKeyState(VK_UP);
		if (key < 0)
			cout << "Up key pressed" << endl;

	} while (1);

	return 0;
}

It works for its purpose (detecting whether the arrow key is pressed), but when it IS pressed, the output outputs like 50 lines. I just want it to output once. I don't like using sleep, because sleep pauses the current thread. That means that if I use sleep(100); then during that 100ms I cannot push the up arrow key again.

Thanks for any help!

EDIT: Just ended up going with getch() from conio.h, it gives me the results I was looking for.
__________________

Last edited by Blupig : 10-26-2011 at 04:21 PM.
Reply With Quote
  #2  
Old 10-28-2011, 07:50 PM
Govind's Avatar
Hero
Highly Respected Highly Trusted Sythe Verified User
 
Join Date: Apr 2005
Posts: 7,068
Default Re: Arrow key detection with GetAsyncKeyState

Code:
while(!GetAsyncKeyState(VK_UP))
    ;
// up key was pressed
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 05:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1