Mega Code Archive

 
Categories / Delphi / Examples
 

How can I detect if a given key was pressed during application during

Title: How can I detect if a given key was pressed during application during 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". program Project1; uses Windows, Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.RES} begin if GetKeyState(vk_F8) MessageBox(0, 'F8 was pressed during startup', 'MyApp', mb_ok); Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end.