Tech Support > Microsoft Windows > Development Resources > GetakeyState Problem
GetakeyState Problem
Posted by Basim Kakakhail on July 18th, 2003


hi all im trying to use GetKeyState function to know that whether an
ALT or Control key is doen or not , the function returns a value of
type SHORT, but i have a confusion as in the documentation it is
wriitem that

"If the high-order bit is 1, the key is down; otherwise, it is up. "


now the question is that what is this high order bit and how would i
extract this .

thanx
Basim

Posted by Dave C. on July 18th, 2003


On 18 Jul 2003, Basim Kakakhail wrote:

The return value will be negative if the key is down. So

altIsDown := GetKeyState(VK_MENU) < 0;

would test if alt is held down where altIsDown is a boolean. Also, I
believe GetASyncKeyState (or some such similar name) give a more immediate
reflection of the keyboard state which may be of interest to you (see
win32 docs). Short is just a 8 or 16 bit signed integer (I can't remember,
caffeine's not working, should go back to bed) so any bitwise ops would
work on it, and the high order bit determintes the sign of the integer
(i.e. positive or negative).

Translate the above code from object pascal to your language of choice,
:= is pascal's assignment operator, like c's =.

Dave