I'm writing an application in Delphi which uses an SQLite3 database. I'd like to be able to start the application while holding some modifier keys, such as CTRL + SHIFT, to signal reinitialization of the database.
How can I capture that the application was started while these keys were held?
Tim has the right answer, but you might need a little more framework:
procedure TForm56.Button1Click(Sender: TObject);
begin
if fNeedReinit then
ReinitializeDatabase;
end;
procedure TForm56.FormCreate(Sender: TObject);
begin
fNeedReinit := False;
end;
procedure TForm56.FormShow(Sender: TObject);
begin
fNeedReinit := (GetKeyState(VK_SHIFT) < 0) and (GetKeyState(VK_CONTROL) < 0);
end;
Change Button1Click with your later event that checks to see if fNeedReinit has been set. You can also set KeyPreview on your main form if you have trouble getting it to catch the key stroke. I just tested the above code and it works, but if you have a splash screen, etc. then it might change things.
if (GetKeyState(VK_SHIFT) < 0) and (GetKeyState(VK_CONTROL) < 0) then
ReinitializeDatabase;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With