加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

德尔福 – 检测同时按下3个键

发布时间:2020-12-15 04:21:59 所属栏目:大数据 来源:网络整理
导读:我想在我的表单中检测按3键,例如Ctrl C N …我需要检测的键入表单将始终以Ctrl开头,接下来是两个字母. 我怎么做的? 解决方法 当其中一个键到达时,您可以查看其他键是否已经关闭.例如.: procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shif
我想在我的表单中检测按3键,例如Ctrl C N …我需要检测的键入表单将始终以Ctrl开头,接下来是两个字母.

我怎么做的?

解决方法

当其中一个键到达时,您可以查看其他键是否已经关闭.例如.:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Shift = [ssCtrl] then begin
    case Key of
      Ord('C'):
        if (GetKeyState(Ord('N')) and $80) = $80 then
          ShowMessage('combo');
      Ord('N'):
        if (GetKeyState(Ord('C')) and $80) = $80 then
          ShowMessage('combo');
    end;
  end;
end;

但是,这也将检测例如N Ctrl C,这是一个不以Ctrl键开头的序列.如果这不符合有效的密钥组合,您可以借助标记保留一些密钥历史记录.以下应仅检测最初以Ctrl开头的序列:

type
  TForm1 = class(TForm)
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    FValidKeyCombo: Boolean;
  end;

...

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if FValidKeyCombo and (Shift = [ssCtrl]) then
    case Key of
      Ord('C'):
        if (GetKeyState(Ord('N')) and $80) = $80 then
          ShowMessage('combo');
      Ord('N'):
        if (GetKeyState(Ord('C')) and $80) = $80 then
          ShowMessage('combo');
    end;
  FValidKeyCombo := (Shift = [ssCtrl]) and (Key in [Ord('C'),Ord('N')]);
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  FValidKeyCombo := False;
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读