Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, i was wondering about the first character in ascii table. It is NULL and my question is if i use it in Visual C++ 6.0 in PreTranslateMessage(MSG* pMsg) function, does that mean that no key is being pressed. Because if i type VK_SHIFT the function will accept it as a Shift key. If i type NULL will it accept it as a non pressed key?
Thanks a lot in advance.
Posted

Consider this:
You sit in your house and want to check when someone knocks on your door. When they knock you get an interrupt and perform some action (such as opening the door). Now you want to check when someone does not knock on your door - how would you do that?
 
Share this answer
 
Virtual keys are not ASCII values. Here's a link to the codes for virtual keys: http://msdn.microsoft.com/en-us/library/dd375731(VS.85).aspx[^] . As you can see, 0x0 is not even listed as a value, so I can only assume that it is undefined.
 
Share this answer
 
v2
You are asking to test if some event has not occurred, which makes little sense. You can test for an event occurring, at which time you perform some action. If the event does not occur then the action is not taken. The message loop can only capture messages that are sent to your application, it cannot signal messages that are not sent.
 
Share this answer
 
To answer your question about checking if any key is pressed, you can use GetKeyboardState[^] and then check all keys in a loop. You could use a timer to periodically check the key states.
 
Share this answer
 
Use a timer to generate events: http://www.developer.com/net/cplus/article.php/603531/Using-Timers-in-MFC-Applications.htm[^]


In your event handler, use GetKeyboardState [^] and then check all keys in a loop.
 
Share this answer
 
So how can i check if a key is not pressed. Is there any possible way to do it instead of something like that
if(isKeyPressed)
{ do something }
else // if key is not pressed
do something else


I need to check if there is no key pressed down in my program.
Is there a function counting that or what?

Can anyone help me? Thanks in advance.
 
Share this answer
 
The problem is I check the event in a function which is called only when the key is pressed. When the key is not pressed the function is not called. I can't check if the key is not down in the function called only when it is down. It doesn't make sense to me.
 
Share this answer
 
I understand what you said in this way:

According to the fact if i am interrupted or not i'm able to understand if someone knocked on the door or not.
 
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