第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使 pynput 鼠標(biāo)偵聽器減少資源消耗

使 pynput 鼠標(biāo)偵聽器減少資源消耗

慕村225694 2023-07-18 10:20:32
我正在嘗試使用pynput 中的此腳本來監(jiān)視我的鼠標(biāo),但它太占用資源了。嘗試import time添加time.sleep(1)后on_move(x, y)功能,但當(dāng)你運(yùn)行它時(shí),你的鼠標(biāo)會(huì)發(fā)瘋。這是整體代碼:import timedef on_move(x, y):? ? print('Pointer moved to {0}'.format((x, y)))? ? time.sleep(1) # <<< Tried to add it over here cuz it takes most of the process.def on_click(x, y, button, pressed):? ? print('{0} at {1}'.format('Pressed' if pressed else 'Released', (x, y)))? ? if not pressed:? ? ? ? return Falsedef on_scroll(x, y, dx, dy):? ? print('Scrolled {0}'.format((x, y)))with Listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll) as listener:? ? listener.join()
查看完整描述

1 回答

?
手掌心

TA貢獻(xiàn)1942條經(jīng)驗(yàn) 獲得超3個(gè)贊

當(dāng)執(zhí)行某些會(huì)阻止代碼的任務(wù)時(shí),您可以使用線程來運(yùn)行代碼。(在您的代碼中,sleep(1)將阻止代碼),無論如何,這在我的電腦上運(yùn)行良好:


from pynput.mouse import Listener

import time

import threading


def task(): # this is what you want to do.

    time.sleep(1)  # <<< Tried to add it over here cuz it takes most of the process.

    print("After sleep 1 second")


def on_move(x, y):

    print('Pointer moved to {0}'.format((x, y)))

    threading.Thread(target=task).start() # run some tasks here.


def on_click(x, y, button, pressed):

    print('{0} at {1}'.format('Pressed' if pressed else 'Released', (x, y)))

    if not pressed:

        return False


def on_scroll(x, y, dx, dy):

    print('Scrolled {0}'.format((x, y)))



with Listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll) as listener:

    listener.join()


查看完整回答
反對 回復(fù) 2023-07-18
  • 1 回答
  • 0 關(guān)注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號