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

The state of the Shift, Ctrl, Alt keys

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.