开发者

How to emulate/spoof keypress event in Haskell?

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 onButto开发者_开发问答nClicked 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.


Generating an event is the Wrong Way. Instead, you should insert your text using the appropriate function for your text widget. For example, for TextBuffers, use textBufferInsertAtCursor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜