user1200972
user1200972

Reputation: 33

Cause a ctrl-v paste to happen from a pygtk app into another window (in Linux)

I'm using pygtk, gtk clipboard, and keybinder. Here's what I'm trying to do.

  1. catch a keypress made when in another windows text field such as a browser
  2. popup a gtk app and process some user input
  3. copy resulting data to gtk clipboard
  4. paste data in clipboard into original window's text field
  5. clear clipboard

I'm catching the key strokes and popping up the window fine. I can copy to the clipboard. I can close the gtk app and return focus to the original windows text field. Only trouble is I don't know how accomplish step 4. As it is right now, the user has to then type ctrl-v to paste from the clipboard into the text field, I'd like to eliminate this keystroke.

Upvotes: 2

Views: 548

Answers (1)

user1200972
user1200972

Reputation: 33

The best I could come up with was using python-wnck to get the window name, then copying to the buffer with gnome-clipboard, and then making a subprocess call to xdotool with the command and the window name.

paste_cmd = 'ctrl+v'
xdo_cmd = 'xdotool search "%s" windowactivate --sync key --clearmodifiers %s'

It seems to work but something native would of been better.

Upvotes: 1

Related Questions