Delphi:我可以区分小键盘的回车键和回车键吗?

发布于 2024-08-16 00:32:54 字数 332 浏览 8 评论 0原文

我有一个古色古香的小应用程序,可以弹出一个用 Delphi 编写的屏幕数字键盘/计算器。我想让它这样,如果您按“输入”(在数字键盘上),您将按“=”,如果您按“返回”(在主键盘上),您将按“确定”。

有一个“确定”按钮,它是表单的默认按钮,可响应按 Enter 或 Return 键。 还有一个 onkeydown 事件处理程序,它可能会捕获 Enter 并作为 vk_return 返回。但它的职责被默认的“确定”按钮所取代。

如果我能知道 return 和 Enter 之间的区别,那么我可以摆脱“确定”按钮上的默认属性,只需在表单按键功能上单击“确定”按钮的单击事件处理程序,但可惜它们都是 VK_RETURN。

I've got a quaint little app that pops up an on screen numberpad/calculator written in Delphi. I'd like to make it so if you pressed 'enter' (on the number pad) you'd be pressing '=' and if you pressed 'return' (on the main keyboard) you'd be pressing 'OK'.

There's an OK button who is the form's default guy which responds to hitting enter or return.
There is also an onkeydown event handler which potentially might capture both Enter and return as vk_return. But its duties are usurped by the default 'OK' button.

If I could know the difference between return and enter, then I could get rid of my default property on the OK button and just do hit the OK button's click event handler on the form key down function, but alas they are both VK_RETURN.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埋葬我深情 2024-08-23 00:32:54

覆盖 WM_KEYDOWN 消息处理程序:

  procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;

实现它,以便它调用除您感兴趣之外的任何内容的祖先。您可以通过键数据消息字段中的“扩展”位来检测返回键和回车键之间的差异:

procedure TForm1.WMKeyDown(var Message: TWMKeyDown);
const
  // Message.KeyData format:
  // [0..15 repCount][16..23 scan code][24 extended bit][25..28 reserved]
  // [29 context][30 previous state][31 transition state]
  KD_IS_EXTENDED = 1 shl 24;
begin
  if Message.CharCode <> VK_RETURN then
  begin
    inherited;
    Exit;
  end;
  if (KD_IS_EXTENDED and Message.KeyData) <> 0 then
    ShowMessage('Keypad Enter')
  else
    ShowMessage('Return');
end;

Override the WM_KEYDOWN message handler:

  procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;

Implement it so that it calls the ancestor for anything but what you're interested in. You can detect the difference between the return key and the enter key by the "extended" bit in the key data message field:

procedure TForm1.WMKeyDown(var Message: TWMKeyDown);
const
  // Message.KeyData format:
  // [0..15 repCount][16..23 scan code][24 extended bit][25..28 reserved]
  // [29 context][30 previous state][31 transition state]
  KD_IS_EXTENDED = 1 shl 24;
begin
  if Message.CharCode <> VK_RETURN then
  begin
    inherited;
    Exit;
  end;
  if (KD_IS_EXTENDED and Message.KeyData) <> 0 then
    ShowMessage('Keypad Enter')
  else
    ShowMessage('Return');
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文