Wxpython,如何用给定的键码创建wx.KeyEvent?
Wxpython, how to create wx.KeyEvent with given key code?
我正在尝试创建一个 wx.KeyEvent 对象,我需要它来模拟 wx.TextCtrl[=23 中的按键=].我不想传播事件(如果可能的话),只是创建一个对象。有办法吗?
我查看了 wxpython.org 上的 wx.KeyEvent 页面,但没有找到任何有用的信息。我唯一的提示是也许我可以创建一个 wx.Event 对象并给它我想要的参数?
编辑:我尝试用 eventType=wx.EVT_KEY_DOWN
实例化一个 Event 对象,但我得到的异常表明它不能是 subclassed/instantiated。难怪,因为我什至如何将参数传递给它。
您可以使用 wx.UIActionSimulator
https://wxpython.org/Phoenix/docs/html/wx.UIActionSimulator.html
生成键、文本和鼠标操作
即
keyinput = wx.UIActionSimulator()
keyinput.Char(ord("z"))
keyinput.Char(ord("\t"))
将模拟一个 "z" 后跟一个制表符
可用的操作有:
> Char Press and release a key.
> KeyDown Press a key.
> KeyUp Release a key.
> MouseClick Click a mouse button.
> MouseDblClick Double-click a mouse button.
> MouseDown Press a mouse button.
> MouseDragDrop Perform a drag and drop operation.
> MouseMove Move the mouse to the specified coordinates.
> MouseUp Release a mouse button.
> Text Emulate typing in the keys representing the given string.
我正在尝试创建一个 wx.KeyEvent 对象,我需要它来模拟 wx.TextCtrl[=23 中的按键=].我不想传播事件(如果可能的话),只是创建一个对象。有办法吗?
我查看了 wxpython.org 上的 wx.KeyEvent 页面,但没有找到任何有用的信息。我唯一的提示是也许我可以创建一个 wx.Event 对象并给它我想要的参数?
编辑:我尝试用 eventType=wx.EVT_KEY_DOWN
实例化一个 Event 对象,但我得到的异常表明它不能是 subclassed/instantiated。难怪,因为我什至如何将参数传递给它。
您可以使用 wx.UIActionSimulator
https://wxpython.org/Phoenix/docs/html/wx.UIActionSimulator.html
即
keyinput = wx.UIActionSimulator()
keyinput.Char(ord("z"))
keyinput.Char(ord("\t"))
将模拟一个 "z" 后跟一个制表符
可用的操作有:
> Char Press and release a key.
> KeyDown Press a key.
> KeyUp Release a key.
> MouseClick Click a mouse button.
> MouseDblClick Double-click a mouse button.
> MouseDown Press a mouse button.
> MouseDragDrop Perform a drag and drop operation.
> MouseMove Move the mouse to the specified coordinates.
> MouseUp Release a mouse button.
> Text Emulate typing in the keys representing the given string.