为什么我的控件不能接受键盘输入? [英] Why won't my control accept keyboard input?

查看:233
本文介绍了为什么我的控件不能接受键盘输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个自定义控件,我正在尝试向其发送输入。它会接受鼠标输入并正确报告MouseDown,MouseMove和MouseUp,但不管什么原因,它都不会接受键盘输入。当我点击它时,它没有得到焦点,并且我按下的任何键都被解释为已经有焦点的任何控制。

这可能是非常简单的事情。我想看的第一个地方是在ControlStyle属性,但我可以看到有关键盘输入帮助文件的唯一的事情是 csNoStdEvents ,它禁用它,我的控制doesn没有那个。那么我需要做些什么才能使我的控件可以接收输入焦点? 解决方案

/ p>


  • MouseDown 中,调用 Windows.SetFocus(Handle) 。根据我的经验,WinAPI函数 SetFocus 通常比VCL的 SetFocus 方法效果更好。 b
  • 响应 WM_GETDLGCODE 消息,回复 Message.Result:= Message.Result或DLGC_WANTCHARS或DLGC_WANTARROWS或DLGC_WANTTAB或DLGC_WANTALLKEYS ;


I've built a custom control that I'm trying to send input to. It will accept mouse input and report MouseDown, MouseMove and MouseUp correctly, but for whatever reason, it won't accept keyboard input. When I click on it, it doesn't receive focus, and any keys I press get interpreted by whatever control had the focus already.

This is probably something really simple. The first place I thought to look was in the ControlStyle property, but the only thing I can see in the helpfile about keyboard input is csNoStdEvents, which disables it, and my control doesn't have that. So what do I need to do to make it so my control can receive input focus?

解决方案

A few things to try:

  • On MouseDown, call Windows.SetFocus(Handle). In my experience, the WinAPI function SetFocus often works better than the VCL's SetFocus method.
  • In response to the WM_GETDLGCODE message, reply with Message.Result := Message.Result or DLGC_WANTCHARS or DLGC_WANTARROWS or DLGC_WANTTAB or DLGC_WANTALLKEYS;

这篇关于为什么我的控件不能接受键盘输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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