sjw rewrite enhanced version - solve the problem that the copied content in the google chrome browser cannot be pasted into the vmware workstation virtual machine

 

Solve the problem that the copied content in the google chrome browser cannot be pasted into the vmware workstation virtual machine. For the previous program, see http://sjwpython.iteye.com/blog/2119756 Here, it has been rewritten and improved today, and it has been corrected many times. The same content ctrl+c does not trigger the bug of auxiliary program execution, eliminating the need to install the xsel tool and improving the program efficiency.

sjw original sharing, reprint please indicate the source: http://sjwpython.iteye.com/blog/2252843

from gi.repository import Gtk, Gdk
import subprocess
import time

CHROME_WINDOW='Google Chrome'
pre_time=time.time()


def sjwCP(*args):
    ''' sjw 2015-10-28 '''

    global pre_time
    task = subprocess.Popen("xdotool getactivewindow getwindowname", shell=True, stdout=subprocess.PIPE)
    winID = task.stdout.read (). rstrip ('\ n')

    now_clip_info=args[0].wait_for_text()
    now_time=time.time()

    if  (winID.endswith(CHROME_WINDOW)) and (now_time-pre_time>0.1):
        if(now_clip_info):
            args[0].set_text(now_clip_info,-1)
   
    pre_time=time.time()


clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)    
clip.connect('owner-change',sjwCP)
Gtk.main()

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326781159&siteId=291194637