[英]Delphi: How do I stop TAction shortcut keys autorepeating?
I'm using a Delphi TActionList, with Shortcut Keys for some actions. 我正在使用Delphi TActionList,其中包含用于某些操作的快捷键。
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. 澄清 :我仍然需要处理多个快速按键 - 它只是我想忽略的自动重复生成的按键。
Intercept the WM_KEYDOWN messages, and look at bit 30 to see if it is auto-repeating. 拦截WM_KEYDOWN消息,并查看第30位以查看它是否是自动重复。 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. 您可能需要启用表单键预览才能使其正常工作。
You can drop TTimer, set TTimer.Interval to value you want (1000 = 1sec), then in TActionList do something like: 您可以删除TTimer,将TTimer.Interval设置为您想要的值(1000 = 1秒),然后在TActionList中执行以下操作:
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 . 另外不要忘记在Timer.OnTimer中禁用计时器。
You can save the last time an action is used and ignore it if the time in between is too short. 您可以保存上次使用操作的时间,如果中间的时间太短,则忽略它。 For a single action you can do like: 对于单个操作,您可以这样做:
procedure TForm.FormCreate(const Sender: TObject);
begin
// ...
FLastActionTime := Now; //
end;
proceudure TForm.Action1Execute(const Sender: TObject);
const
cThreshold = 1/(24*60*60*10); // 0.1 sec
begin
if Now-FLastActionTime<cThreshold then
Exit; // Ignore two actions within 0.1 sec
FLastActionTime := Now;
end;
You can combine this with the solution of dmajkic to get a more generic aproach. 你可以将它与dmajkic的解决方案结合起来,以获得更通用的方法。 And if you are really ambitious, you can create a new version of TAction/TActionlist. 如果你真的雄心勃勃,你可以创建一个新版本的TAction / TActionlist。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.