1. Home
  2. Computing & Technology
  3. Delphi Programming

The state of the Shift, Ctrl, Alt keys

By Zarko Gajic, About.com

The following functions can be used to check if the Shift, Ctrl or Alt key(s) are pressed...

~~~~~~~~~~~~~~~~~~~~~~~~~
function CtrlDown : Boolean;
var
   State : TKeyboardState;
begin
   GetKeyboardState(State) ;
   Result := ((State[vk_Control] And 128) <> 0) ;
end;

function ShiftDown : Boolean;
var
   State : TKeyboardState;
begin
   GetKeyboardState(State) ;
   Result := ((State[vk_Shift] and 128) <> 0) ;
end;

function AltDown : Boolean;
var
   State : TKeyboardState;
begin
   GetKeyboardState(State) ;
   Result := ((State[vk_Menu] and 128) <> 0) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Hide a Process in the 'Close Program' Window
« Path shortener: c:\AB\C...DE\F.ghi

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TEdit, TMaskEdit
  6. The state of the Shift, Ctrl, Alt keys

©2009 About.com, a part of The New York Times Company.

All rights reserved.