如何在 Haskell 中模拟/欺骗按键事件?
如何在 Haskell 中模拟/欺骗按键事件?
我的 Gui 中有一个屏幕数字键盘,我想用它来写入窗口中的多个文本条目。键盘由按钮小部件组成,我想要做的是让 onButtonClicked
处理程序发送 keyPressEvent
,以便将适当的字符/数字写入到文本条目中有焦点。我首先查看 Graphics.UI.Gtk.Gdk.Events 并创建了一个按键事件,但
Event my1Event = Key True True Graphics.UI.Gtk.Gdk.Events.currentTime [] False False False 0xffb1 "KP_1" Nothing
我不知道如何调度该事件。无论如何,事实证明 Event 已被弃用,应该使用 EventM。我发现 widgetEvent :: WidgetClass self =>自我->
。 api 中写着:Graphics.UI.Gtk.Abstract.Widget
中的 EventM t Bool
很少使用的函数。此函数用于在小部件上发出事件信号(如果不使用此函数,则不应发出这些信号)。如果您想合成一个事件,请不要使用此函数;相反,请使用 mainDoEvent,以便事件的行为就像在事件队列中一样。
因此,我查看了 Graphics.UI.Gtk.General.General
中的 mainDoEvent :: EventM t ()
但不确定如何使用 EventM
创建一个按键,但找不到正在使用的 mainDoEvent
示例。有人可以告诉我如何使用 EventM
创建按键事件并将其传递给 mainDoEvent
或其他方式来执行此操作吗?谢谢。
How to emulate/spoof keypress event in Haskell?
I have an onscreen number keypad in my Gui which I want to use to write into a number of text entrys in the window. The Keypad is made up of button widgets and what I want to do is have the onButtonClicked
handler send a keyPressEvent
so that the appropriate char/number is written into the text entry that has focus. I started by looking at Graphics.UI.Gtk.Gdk.Events
and made an keypress event
Event my1Event = Key True True Graphics.UI.Gtk.Gdk.Events.currentTime [] False False False 0xffb1 "KP_1" Nothing
I couldn't figure out how to dispatch this event. Anyway it turns out Event is deprecated and should use EventM. I found widgetEvent :: WidgetClass self => self -> EventM t Bool
in Graphics.UI.Gtk.Abstract.Widget
. In the api it says:
Rarely-used function. This function is used to emit the event signals on a widget (those signals should never be emitted without using this function to do so). If you want to synthesize an event though, don't use this function; instead, use mainDoEvent so the event will behave as if it were in the event queue.
So I looked at mainDoEvent :: EventM t ()
in Graphics.UI.Gtk.General.General
but am unsure as how to use EventM
to create a keypress and couldn't find an example of mainDoEvent
in use. Can anybody advise me how to create a keypress event using EventM
and pass it to mainDoEvent
or some other way to do this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
生成事件是错误的方式。相反,您应该使用文本小部件的适当函数插入文本。例如,对于
TextBuffer
,请使用 textBufferInsertAtCursor。Generating an event is the Wrong Way. Instead, you should insert your text using the appropriate function for your text widget. For example, for
TextBuffer
s, use textBufferInsertAtCursor.