Actually I learned that a long time ago and keep an updated copy on
my desktop. But having read the documentation I still didn't understand why
it was necessary to mask out the other bits in one situation and not
another. GetKeyState(VK_SHIFT) works fine by itself so evidently it is
returning the value of the high order bit. Also I don't have a clue as to
what $8000 means or how it works...I'm just guessing...remember no comp sci
at all! Now Malcolm is saying that simply if (key=VK_F1) and (ssShift in
Shift) then should work as well, but why then doesn't if (key=VK_F1) and
(Key = VK_SHIFT) then work as well? They both check for any Shift Key? Is
it a syntax problem that you cannot check for two virtual key codes
together?
from Robert Meek dba Tangentals Design CCopyright 2006
"When I examine myself and my methods of thought, I come to the conclusion
that the gift of Fantasy has meant more to me then my talent for absorbing
positive knowledge!"
Albert Einstein
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Rob Kennedy
Sent: Tuesday, April 25, 2006 10:19 AM
To: Borland's Delphi Discussion List
Subject: Re: Virtual key codes
Robert Meek wrote:
> Please bear with me as this is an area I have little or no knowledge
> in. I understand you need to check for the particular key in the
OnKeyDown
> event, but I was assuming in error that the "and $80)> 0 was doing the
same.
Sorry, it should actually be $8000; GetKeyState returns a Word, not a Byte.
> How exactly does this part work? You say it masks out the other
> bits in the byte returned by GetKeyState, but why is that necessary in
this
> example when it wasn't in the other I mentioned earlier where I had
> originally been using GetAsynchKeyState? That now works perfectly without
> having to mask out the other bits.
The documentation says that the high-order bit represents whether the
key is down. The low-order bit tells whether a togglable key is toggled.
The documentation doesn't say anything about the 14 remaining bits, so
you can't assume what their values will be. Since we're only interested
in the value of bit 15, mask out the rest.
Whenever you see anyone mention an API function, the *first* thing you
should do to learn more about it is to read the documentation on MSDN.
And not just the one-sentence blurb at the top. Read the whole thing,
including the descriptions of the parameters and the return value, and
especially the "remarks" section, if there is one, since that will
usually include notes on when it is appropriate to use a function in
preference over some other function, on where certain parameter values
are supposed to come from, on what the function's inverse is, and
sometimes on what the rest of the OS does in response to a call to that
function.
And note that the Win32 help that comes with Delphi is *not* a
substitute for MSDN. If you have a convenient Internet connection, just
bookmark the site. If you don't have the luxury of being online while
you program, then download a copy or order it on DVD. The MSDN library
is indispensable for anyone writing programs for Windows.
--
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi