Delphi - 使用TApplicationEvents OnShortCut事件来检测Alt + C按键 [英] Delphi - Using the TApplicationEvents OnShortCut event to detect Alt+C key presses

查看:1752
本文介绍了Delphi - 使用TApplicationEvents OnShortCut事件来检测Alt + C按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TApplicationEvents OnShortCut事件来获取Delphi程序中的应用程序键盘快捷方式。

I am using TApplicationEvents OnShortCut event to get application keyboard short cuts in a Delphi program.

使用以下代码:

procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean) ;
begin
   if (Msg.CharCode = VK_F9) then
   begin
     ShowMessage('F9 pressed!') ;
     Handled := True;
   end;
end;

问题:

当ALT C被按下时

推荐答案

像这样:

procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey;
  var Handled: Boolean);
begin
  if (Msg.CharCode = Ord('C'))
    and (HiWord(Msg.KeyData) and KF_ALTDOWN <> 0)
  then begin
    ShowMessage('Alt+C pressed!') ;
    Handled := TRUE;
  end;
end;

请注意,使用Alt和某些键只是快捷方式的不错选择,因为系统使用这些用于激活菜单项或对话框控件。

Please note that using Alt and some key only is a bad choice for a shortcut, as the system uses these to activate menu items or dialog controls.

这篇关于Delphi - 使用TApplicationEvents OnShortCut事件来检测Alt + C按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆