简体   繁体   English

Delphi:如何停止TAction快捷键自动重复?

[英]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.

相关问题 如何将 TAction 的快捷方式设置为 Ctrl + Numpad 0? - How can I set a TAction's Shortcut to Ctrl + Numpad 0? Delphi TAction ShortCut不适用于子表单 - Delphi TAction ShortCut doesn't work for child form 如何禁用TAction.Shortcut或TMenuItem.Shortcut? - How to disable TAction.Shortcut or TMenuItem.Shortcut? TAction.ShortCut无法在动态创建的TAction中工作 - TAction.ShortCut not working in dynamically created TAction 已经被 Delphi TAction 处理过的 ShortCut-Key 可以被允许进一步传播到其他组件吗? - Can ShortCut-Key, that has been processed by Delphi TAction, be allowed to propagate further to other components? 如何更改Delphi的“运行”和“添加断点”快捷键? - How can I change Delphi's 'Run' and 'Add Breakpoint' shortcut keys? 如何在Delphi中使用IVBSAXXMLReader停止解析XML文档? - How do I stop parsing an XML document with IVBSAXXMLReader in Delphi? Delphi Direct Oracle Access,DOA 4.0.7.1,TOracleEvent.Stop挂起,如何停止它? - Delphi Direct Oracle Access, DOA 4.0.7.1, TOracleEvent.Stop Hangs, How do I stop it? 如何阻止调试器进入Delphi提供的单元? - How do I stop the debugger from stepping into Delphi-supplied units? 快捷方式在第一个创建的表单上触发TAction,而不是在具有焦点的表单上 - Shortcut triggers TAction on first created form instead of form with focus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM