使用Python3记录Trackpoint活动并模拟点击

时间:2019-03-06 22:37:49

标签: python-3.x multithreading

我是linux-thinkpad用户,我发现lenovo(硬件级别)已删除了跟踪点的点击功能,因此我尝试通过检查跟踪点的活动来模拟功能。

这个想法是要记录跟踪点的运行时间,如果跟踪点运行的时间少于0.3秒,请点击鼠标左键 这是不完整的代码:

import time 
import subprocess
import threading
from pynput.mouse import Button, Controller

def main():
    # subprocess.call('gsettings set org.gnome.desktop.peripherals.touchpad tap-to-click true', shell=True)
    mouse = Controller()
    # monitoring trackpoint event
    p = subprocess.Popen('xinput test 12', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    clickTime = [0, 0]
    startTime = [0, 0]
    def checkTime():
        count = 0
        while True:
            out = p.stdout.readline()
            # if len(out) > 1 and count == 0:
            #     count = 1
            #     startTime[0] = time.time()
            # if len(out) < 1:
            #     count = 0
            #     break
            clickTime[0] = time.time()
            # I have no idea how to update the startTime, the break is not working

    t = threading.Thread(target=checkTime)
    t.start()


    lastTime = 0
    count = 0
    gap = 0
    while True:
        active = time.time() - clickTime[0]
        print ('active for', active)

        if active < 0.3:
            click_moment = time.time()
            mouse.click(Button.left, 1)
            print("clicking")

        time.sleep(0.25)

    retval = p.wait()

if __name__ == '__main__':
    main()

0 个答案:

没有答案