Re: The escape key



Don't forget that OnKeyDown / OnKeyUp triggers with the _key_ which is
pressed, OnKeyPress triggers with the ASCII value which is the _result_
of the hardware key being pressed.

Hence if you want to know whether a _key_ has been activated use
OnKeyDown / Up. In those event handlers use Microsoft's VK_???
"virtual-key" constants.

If you want to check a key-press in OnKeyPress and also want to check
for modifiers (shift, control, alt) then use ...

if GetKeyState(VK_SHIFT {VK_CONTROL, VK_MENU}) < 0 then ...

.... as well as your ASCII key char value.

GetKeyState returns with the high bit set (ie is negative) if pressed.
For togglable keys (numlock, insert, scroll-lock) the low order bit is
set if the function is set.

Search help for "virtual-key codes" for a full list.

Note that (in D3 at least) the VK_A to VK_Z are not declared by Delphi
but are the ASCII values as returned by Ord() or used in Chr().

Alan Lloyd

.


Quantcast