954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

GetKeyState syntax

At the beginning of an "IF" statement, I have:

if (SHORT GetKeyState(int 48)==1){


When compiling I get a syntax error just before the constant, and I've played around with it a bit, but haven't found what to do.

Could someone fix this or explain to me why it's not working?

Khishin
Newbie Poster
23 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Here is the MSDN entry for the function:
GetKeyState()

Khishin
Newbie Poster
23 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Prototypes tell you the expected types, but when you call a function you don't include the type -- the type is inherently part of the variable or literal being used in the call. That is,

if (GetKeyState(48)==1){
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

I had realized that a bit after I posted, but I seem to be getting the low bit instead of the high bit, which is the one I need.

Isn't there a HIGH() operator or something?

Khishin
Newbie Poster
23 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

How can I take only the high order bit from that command?

Khishin
Newbie Poster
23 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

>How can I take only the high order bit from that command?
Here's a slight push in the direction of a solution:

#define bit(i) (1UL << (i))

You can use it to test a certain bit by ANDing the result of bit(n) with the value:

if ((GetKeyState(48) & bit(7)) != 0)
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You