Click here to Skip to main content
15,917,618 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, i'm using VC++ 6.0 and i have a problem with pressed keys in my program. When i press some key i make my program do something. For example i have a falling circle in a timer and if i press 'Z' when the circle gets coordinate Y = 500 it makes my score increased by 100. But if i do not press 'Z' when the circle gets 500
it must make my scores = 0; I made it to increase my points, but i don't know how to make it null the scores if 'Z' is NOT pressed.
I hope someone can help me. Thanks in advance.
Posted
Updated 28-Dec-09 10:57am
v3

int inc = -score;
if (Z is pressed)
    inc = 100;
score += inc;
 
Share this answer
 
Thanks a lot about your answer but i have functions where i count if 'Z' is pressed and when it's pressed the function is called and my score is increased. The hard stuff to me is how to check if 'Z' is not pressed, i mean i don't know where i need to check if 'Z' isn't pressed down. In the function i check if it is and it works, but where to check if it isn't.
:( I saw a function called GetKeyState() but i have no idea if i have to use it. My questions might sound stupid to you, but i'm just 16 years and beginner in programming.
 
Share this answer
 
Probably you need GetAsyncKeyState function [^]. You may use it this way:
bool isZKeyDown()
{
  // test if the Most Significative Bit (MSB, i.e. bit 15) is one.
  return ((GetAsyncKeyState('Z') >> 15) == 1);
}



BTW: you should edit your original post, instead of posting new answers.
:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900