whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

63 Visitors Online


 
...detect more than 2 keys being pressed within a form?
Autor: Radikal, Q3 Team
[ Print tip ]  

Tip Rating (28):  
     


{
  I would like to detect more than 2 keys being pressed within a form.
  For example I would like to know if the user pressed    time. The onkeydown seems to only check for one or two keys max but surely
  you can determine what keys are currently down.
}

// You can use GetKeyState:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If 
((GetKeyState(VK_CONTROL) AND 128)=128) and
     
((GetKeyState(VK_F5)      AND 128)=128) and
     
((GetKeyState(ord('8'))   AND 128)=128)
    then
      
ShowMessage('CTRL+F5+8 Pressed');
end;

( Remember: Form1.Keypreview := TRUE )


// Or you can read the entire KeyBoard Status,
// and later check for the three keys:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
   
KeybState: TKeyboardState;
begin
  
GetKeyboardState(Teclado);
  If ( (KeybState[VK_CONTROL] and 128)=128 ) and
     
( (KeybState[VK_F5]      and 128)=128 ) and
     
( (KeybState[Ord('8')]   and 128)=128 )
    then
      
ShowMessage('CTRL+F5+8 Pressed');
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners