Mega Code Archive

 
Categories / Delphi / Forms
 

How to detect more than 2 keys being pressed within a form

Title: How to detect more than 2 keys being pressed within a form // 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;