Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


hold back key


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Alexiev   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 August 2001 - 08:15 AM

I don''t know how kan I make my heros move light. I just want to know how can I understand if key is press. Not to write from Keyboard buffer and wait 1/4 sec after first read from buffer. QBASIC, PASCAL, C, C++, VB, PERL,

Sponsor:

#2 GameDev135   Members   -  Reputation: 133

Like
Likes
Like

Posted 14 August 2001 - 03:39 AM

In C++, define these two macros at the top of the file:

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 :0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

IMPORTANT- make sure that each macro fits onto 1 line.

Also make sure that you include:
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <stdio.h>// i'm not sure if you actually need
#include <stdlib.h>// these last 3
#include <math.h>

then you can test for certain specific keys,
such as:
if (KEYDOWN(VK_UP )) {
//move character up
}
if (KEYUP(VK_UP)) {
// user released the up key
}
This only works for keys such as VK_SPACE, VK_RETURN, VK_F1, VK_UP, VK_DOWN, etc. (special keys). It doesnt work for regular keys like "a" or "b" I'm not actually sure how to do that. If anyone knows I would appreciate that.

Hope this helps

Dan

Edited by - GameDev135 on August 14, 2001 12:30:54 PM

#3 Magicdude   Members   -  Reputation: 134

Like
Likes
Like

Posted 14 August 2001 - 03:59 AM

To check for keys like A and B, just use

  
if ( KEYDOWN( ''A'' ) )
// Do stuff



easy eh




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS