德尔福:如何分配的向上箭头键盘快捷键操作/菜单项,并保持它实际用于导航列表控件(列表框/ VTV)?

StackOverflow https://stackoverflow.com/questions/2176519

请帮助我?如何分配一个向上的箭头的键盘快捷键来操作或菜单项,并保持它实际在同一时间浏览列表控件(如列表框/虚拟树视图/其他)

谢谢!

有帮助吗?

解决方案

您的评论:

  

又有怎样的Winamp播放器?它具有音量/调低音量功能分配给向上箭头键和向下箭头键相应..好吧,如果这不可能在Delphi中,然后...

但可以肯定的是可能的,但绝不是一个好主意,做,对Windows用户体验互动指南。

但是,如果你在实现这个设定,这里的如何。覆盖表单类以下方法包含动作部件:

function IsShortCut(var Message: TWMKey): Boolean; override;

和在它可以防止上下键触发,从它们的快捷键的操作为:

function TWeirdForm.IsShortCut(var Message: TWMKey): Boolean;
begin
  if (Message.CharCode in [VK_UP, VK_DOWN])
    // insert test whether message needs to go to the focused control instead
    and (...)
  then begin
    // insert calls to code that should be executed instead
    Result := False;
    exit;
  end;
  inherited;
end;

请注意,您应该测试正确的换挡状态太,并检查你的代码不会破坏任何其他窗口的行为用户期望,就像用箭头键在窗口的移动。

其他提示

在形式属性中设置KeyPreview := true

然后在构成写入事件KeyUp事件,检查是否向上键被按下,使其调用菜单项(关于这个叫措施1情况下菜单项):

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if (Key = VK_UP) and (ActiveControl = ListBox1)then
    Action11.Click;
end;

procedure TForm1.Action11Click(Sender: TObject);
begin
  if ListBox1.ItemIndex >=0  then
    ShowMessage(ListBox1.Items[ListBox1.ItemIndex]);
end;

如果您需要的措施1被即使电流控制是不是列表框中执行,删除and声明

IF部分
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top