Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get Current KeyBorard''s State?

Status
Not open for further replies.

SonicChen

Programmer
Feb 14, 2004
62
CN
i need to know run time Key State such as Shift and Ctrl and Alt.

way to gold shines more than gold
 
A useful type that delphi provides with most mouse and key events is TShiftState. You can check it to see the state of Shift, Alt and Ctrl keys.

Example:
I have put this code in the OnKeyDown event of an TEdit box.
Code:
procedure TForm1.Edit1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if Shift = [ssShift] then ShowMessage('Shift pressed');
  if Shift = [ssAlt] then ShowMessage('Alt pressed');
  if Shift = [ssCtrl] then ShowMessage('Ctrl pressed');
end;

Alternatively check out this link:
Clive [infinity]
 
Check GetAsyncKeyState/GetKeyState in the SDK.

buho (A).
 
yeah winapi better.
thanks

way to gold shines more than gold
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top