Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: How do I stop TAction shortcut keys autorepeating?

I'm using a Delphi TActionList, with Shortcut Keys for some actions.

I want to prevent certain actions from being triggered multiple times by keyboard auto-repeat, but I do not want to affect auto-repeat operation globally. What's the best way of doing this?

Clarification: I still need to handle multiple fast keypresses - it's only the keypresses generated by auto-repeat that I want to ignore.

like image 428
Roddy Avatar asked Oct 15 '25 04:10

Roddy


2 Answers

Intercept the WM_KEYDOWN messages, and look at bit 30 to see if it is auto-repeating. If it is, just don't pass on the message as usual and it will not be seen.

You may need to enable form key-preview to make this work.

like image 168
mj2008 Avatar answered Oct 18 '25 14:10

mj2008


You can drop TTimer, set TTimer.Interval to value you want (1000 = 1sec), then in TActionList do something like:

procedure TfrmMain.ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
begin
  if Timer1.Enabled then 
  begin
    Handled := True;
    Exit;
  end;

  Handled := false; 
  Timer1.Enabled := true;     
end;

Also don't forget to disable timer in Timer.OnTimer.

like image 28
dmajkic Avatar answered Oct 18 '25 13:10

dmajkic