简体   繁体   English

为什么没有捕获关键事件c ++ WxWidgets?

[英]why are Key events c++ WxWidgets not being caught?

Good day guys 大家好

I am using WxWidgets 2.8. 我正在使用WxWidgets 2.8。 I have created a grid like interface using text boxes. 我已经使用文本框创建了一个类似于网格的界面。 I would like to change the values in text boxes by simply navigating to them using the arrow keys. 我想通过使用箭头键导航到文本框中的值来更改它们。

I have set up a panel in which the text boxes are placed, then added a onkeydown event which should just display a message when a key is pressed. 我设置了一个放置文本框的面板,然后添加了onkeydown事件,该事件仅在按下某个键时显示一条消息。 This does not work. 这是行不通的。

I have tried oncharevent, and even adding the the events to the wxFrame. 我尝试过oncharevent,甚至将事件添加到wxFrame。

Why can I not catch the key events? 为什么我无法捕获关键事件?

Only the currently focused window gets the key events and the frame will never have focus if it has any children taking it, such as text controls. 只有当前聚焦的窗口才能获取关键事件,并且如果框架有任何子级(例如文本控件),则该框架将永远不会聚焦。

Also do consider using wxWidgets 3.0 for any new code, in particular it provides Bind() which can be convenient for handling key events from all your controls in a single place if this is what you want to do. 还要考虑对任何新代码使用wxWidgets 3.0,特别是它提供Bind() ,如果您要这样做,它可以方便地在一个地方处理所有控件中的键事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM