Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
New related comments Number of comments in the last 48 hoursPlay WAV files 1 new comments
|
Get Shift/ Ctrl/ Alt Key state
1 comments. Current rating: (1 votes). Leave comments and/ or rate it.
This code determines the state of shift, alt and ctrl keys.
You can do this while your application is initializing, in order to do something or not to do something.
Keywords: keystate, keyboard state
Note: (Thanks to Mary Atkins-Shington for reporting this)
GetKeyState and GetAsyncKeyState only work with Win95, Win98, NT4, Terminal Server and Windows 2000.
But on WinME it always returns zero. These two functions are simply skipped by Millenium Edition!
Official explanation from Microsoft:
Intentionally disabled.
It didn't work all that well on some newer hardware, and worked less well with the passage of time, so it was fully disabled in ME.  | |  | | function HighOrderBitSet (theWord: Word): Boolean;
const
HighOrderBit = 15;
type
BitSet = set of 0..15;
begin
HighOrderBitSet := (HighOrderBit in BitSet(theWord));
end;
..
begin
..
AltKeyDown := HighOrderBitSet(Word(GetKeyState(VK_MENU)));
CtrlKeyDown := HighOrderBitSet(Word(GetKeyState(VK_CONTROL)));
ShiftKeyDown := HighOrderBitSet(Word(GetKeyState(VK_SHIFT)));
LeftShiftKeyDown := HighOrderBitSet(Word(GetKeyState(VK_LSHIFT)));
end.
| |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|