Cov txheej txheem:

Txiav Txim Screenshots Hauv Windows Nrog Python Script: 4 Kauj Ruam
Txiav Txim Screenshots Hauv Windows Nrog Python Script: 4 Kauj Ruam

Video: Txiav Txim Screenshots Hauv Windows Nrog Python Script: 4 Kauj Ruam

Video: Txiav Txim Screenshots Hauv Windows Nrog Python Script: 4 Kauj Ruam
Video: 20 MOMENTS YOU WOULDN'T BELIEVE IF NOT FILMED 2024, Hlis ntuj nqeg
Anonim
Txiav Txuag Screenshots hauv Windows Nrog Python Script
Txiav Txuag Screenshots hauv Windows Nrog Python Script

Feem ntau hauv lub qhov rais, kom txuag tau lub vijtsam (luam tawm lub vijtsam) ua ntej peb yuav tsum tau thaij duab thiab tom qab ntawd qhib xim, tom qab ntawd muab tshuaj txhuam thiab tom qab ntawd thaum kawg khaws nws.

Tam sim no, kuv yuav qhia koj yuav ua li cas ua haujlwm nab hab sej kom siv nws.

Qhov kev zov me nyuam no yuav tsim daim nplaub tshev npe hu ua 'txhaj tshuaj' hauv koj lub desktop thiab txuag cov duab hauv lub vijtsam tshiab hauv qhov txhaj tshuaj nrog lub sijhawm nws tau ua thaum koj nias PrtScn qhov tseem ceeb thiab tawm ntawm qhov program thaum Ctrl + PtrScn raug nias.

Koj yuav xav tau cov nab hab sej 3.7 teeb tsa, cov ntawv nyeem kho (kuv siv Sublime Text 3), autopy thiab pynput sej pob

Kauj ruam 1: Txhim Kho Autopy thiab Pynput

Tom qab txhim kho nab hab sej 3.7, qhib cmd (hais kom sai) thiab ntaus hauv qab no:

pib nruab autopy

nias nkag mus Qhov no yuav nruab pob autopy. Tom qab qhov no ua tiav, ntaus:

pip nruab pynput

txhawm rau nruab pob pynput.

Kauj ruam 2: Coding

Qhib koj cov ntawv sau, thiab ntaus hauv qab no:

import hnub tim

ntshuam os ntshuam autopy los ntawm pynput.keyboard ntshuam Ntsiab, Mloog

ces ntaus:

exit_combination = {Key.ctrl_l, Key.print_screen}

current_pressed = teeb tsa ()

qhov no teeb tsa qhov tseem ceeb ua ke kom tawm ntawm qhov haujlwm thaum tus neeg siv nias ua ke ntawm cov yuam sij, qhov no, nws yog Sab laug Ctrl + PrtScn.

Ces ntaus:

path = "c: // Users //"+os.getlogin ()+"// Desktop // shots //"+str (datetime.date.today ())

sim: os.makedirs (txoj kev) tsuas yog FileExistsError: dhau

Qhov no yuav ua rau daim nplaub tshev uas muaj npe txhaj tshuaj hauv koj lub desktop thiab hauv nws lwm daim nplaub tshev nrog rau hnub tam sim no os.getlogin () tau siv kom tau txais tus neeg siv tam sim no.

Ces ntaus:

nrog Mloog (on_press = on_press, on_release = on_release) ua tus mloog:

mloog.join ()

ntawm no Tus Neeg Ua Haujlwm mloog mloog rau cov yuam sij thiab koom () tau siv los sau lawv kom txog thaum tso tawm.

Tam sim no cia peb txheeb xyuas lub luag haujlwm, ntaus lawv tom qab cov lus tshaj tawm, ua ntej 'exit_combination'.

Peb yuav tsum txhais 3 lub luag haujlwm: on_press, on_release, thiab check_key.

on_press thiab on_release yog cov haujlwm uas yuav tsum tau ua los ntawm Tus Ua Haujlwm mloog.

def on_press (qhov tseem ceeb): kos_key (qhov tseem ceeb) yog qhov tseem ceeb hauv exit_combination: tam sim no_pressed.add (qhov tseem ceeb) yog tam sim no_pressed == exit_combination: mloog.stop ()

txoj haujlwm no siv qhov ntsuas 'qhov tseem ceeb' thiab xa nws mus rau qhov check_key (qhov tseem ceeb) ua haujlwm. Tom qab ntawd nws kuaj xyuas yog tias tus yuam sij nyob hauv kev tawm ua ke, piv txwv li ua ke ntawm cov yuam sij los nias kom tawm qhov haujlwm, yog tias nws yog, tom qab ntawd nws tsis ua tiav qhov ua haujlwm mloog.

Ces ntaus:

def on_release (qhov tseem ceeb): sim: tam sim no_pressed.remove (qhov tseem ceeb) tshwj tsis yog KeyError: dhau

qhov no tshem tus yuam sij los ntawm cov teeb tsa tam sim no.

Ces ntaus:

def check_key (key): yog qhov tseem ceeb == Key.print_screen: txhaj = autopy.bitmap.capture_screen () tam sim no = datetime.datetime.now () timenow = now.strftime ("%H_%M_%S") txoj kev = " c: // Users // "+os.getlogin ()+" // Desktop // shots // "+str (datetime.date.today ()) sim: shot.save (path+'//'+timenow+'-p.webp

Txoj haujlwm no sib piv qhov tam sim no nias qhov tseem ceeb nrog tus lej tshwj xeeb (print_screen key), yog tias nws sib phim, tom qab ntawd nws yuav siv lub vijtsam siv lub tsev qiv ntawv autopy's capture_screen () thiab txuag nws mus rau qhov hloov pauv 'txhaj tshuaj'.

Tom qab ntawd nws rov txhais txoj kev hloov pauv mus rau siv hnub tam sim no (qhov no tau ua tiav los tsim daim nplaub tshev tshiab nrog rau hnub tam sim no kom txawm tias tus neeg siv tsis rov pib dua qhov haujlwm tom qab 12:00 teev tsaus ntuj, cov duab yuav raug khaws tseg hauv daim nplaub tshev tshiab nrog hnub hloov tshiab.

Ib nqe lus sim tau siv los khaws daim duab rau hauv daim nplaub tshev nrog hnub tim tam sim no. Yog tias tsis muaj daim nplaub tshev, nws yuav tsim FileNotFoundError uas tau ua los ntawm cov lus tshwj xeeb los ntawm kev ua daim nplaub tshev thiab tom qab ntawd khaws nws.

Tam sim no tseg cov cai nrog.py ncua ntxiv.

Txheeb cov ntaub ntawv sej yog tias nws tsis meej ~

Kauj Ruam 3: Kuaj Cov Cai thiab Khiav Tsis Muaj Qhov rai Console

Kuaj Cov Cai thiab Khiav Tsis Muaj Qhov rai Console
Kuaj Cov Cai thiab Khiav Tsis Muaj Qhov rai Console

Yog tias koj cov ntawv kho mob txhawb nqa txoj cai, tom qab ntawd ua nws. Yog tias tsis yog, tom qab ntawd ob npaug nyem rau cov ntaub ntawv nab hab sej kom ua nws.

Yog tias koj tsis tau txais ib qho yuam kev, thov ua tsaug.

Tam sim no, yog tias koj tsis xav pom lub qhov rai console txhua zaus koj siv txoj cai, tom qab ntawd hloov cov ntaub ntawv txuas ntxiv los ntawm.py rau.pyw.

Lub hauv paus tseem ceeb ua ke kom tawm ntawm txoj haujlwm yog sab laug ctrl + prtscn, koj tuaj yeem hloov qhov no los ntawm kev hloov nws hauv exit_combination.

Yog tias koj nyiam qhov kev qhia no, thov pov npav rau kuv hauv kev sib tw

Pom zoo: