Mega Code Archive

 
Categories / Delphi / API
 

How can i detect if a given key was pressed during application during startup

Question: How can I detect if a given key was pressed during application startup? Answer: Use the Windows API function GetKeyState() to determine if a key is pressed in the main project source. To get to the main project's source file, select from the IDE's main menu, select "View">>"ProjectSource". Example: program Project1; uses Windows, Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.RES} begin if GetKeyState(vk_F8) < 1 then MessageBox(0, 'F8 was pressed during startup', 'MyApp', mb_ok); Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end.