To scratch a personal itch, I'm writing something like a cross between a character map and an on-screen keyboard. When the user selects a character, I'd like to insert it into another application, specifically, the application that would next receive focus if my application were closed. Is there any way to do this? Right now, I work around it by just putting the character into the clipboard and terminating, leaving the user to hit paste in the other application, but usage would be far more strea开发者_如何学Cmlined if I could just insert the text programmatically.
I'm doing this in GTK and expect to run it only on Linux. But cross-platform solutions are also appreciated, and if GTK can't do it but some other toolkit can, I'll gladly switch.
This sounds like you should use libwnck, which is a GTK-related library that lets you manipulate windows on the desktop. The documentation is a little sparse, but the function wnck_screen_get_previously_active_window()
seems promising.
From a WnckWindow
you can get an X window ID, and perhaps from there you can use the X libraries to send a paste message (or even send it a "Ctrl-V" keypress event), perhaps with XSendEvent()
.
Very good question, by the way. I wish I could answer it more knowledgeably.
精彩评论