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

Reply via email to