发布时间:2019-09-22 07:49:53编辑:auto阅读(2001)
代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pythoncom
import pyHook
import time
def onMouseEvent(event):
"处理鼠标事件"
fobj.writelines('-' * 20 + 'MouseEvent Begin' + '-' * 20 + '\n')
fobj.writelines("Current Time:%s\n" % time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
fobj.writelines("MessageName:%s\n" % str(event.MessageName))
fobj.writelines("Message:%d\n" % event.Message)
fobj.writelines("Time_sec:%d\n" % event.Time)
fobj.writelines("Window:%s\n" % str(event.Window))
fobj.writelines("WindowName:%s\n" % str(event.WindowName))
fobj.writelines("Position:%s\n" % str(event.Position))
fobj.writelines('-' * 20 + 'MouseEvent End' + '-' * 20 + '\n')
return True
def onKeyboardEvent(event):
"处理键盘事件"
fobj.writelines('-' * 20 + 'Keyboard Begin' + '-' * 20 + '\n')
fobj.writelines("Current Time:%s\n" % time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
fobj.writelines("MessageName:%s\n" % str(event.MessageName))
fobj.writelines("Message:%d\n" % event.Message)
fobj.writelines("Time:%d\n" % event.Time)
fobj.writelines("Window:%s\n" % str(event.Window))
fobj.writelines("WindowName:%s\n" % str(event.WindowName))
fobj.writelines("Ascii_code: %d\n" % event.Ascii)
fobj.writelines("Ascii_char:%s\n" % chr(event.Ascii))
fobj.writelines("Key:%s\n" % str(event.Key))
fobj.writelines('-' * 20 + 'Keyboard End' + '-' * 20 + '\n')
return True
if __name__ == "__main__":
'''
Function:操作SQLITE3数据库函数
Input:NONE
Output: NONE
author: socrates
blog:http://blog.csdn.net/dyx1024
date:2012-03-1
'''
#打开日志文件
file_name = "D:\\hook_log.txt"
fobj = open(file_name, 'w')
#创建hook句柄
hm = pyHook.HookManager()
#监控键盘
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
#监控鼠标
hm.MouseAll = onMouseEvent
hm.HookMouse()
#循环获取消息
pythoncom.PumpMessages()
#关闭日志文件
fobj.close()
--------------------Keyboard Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:01
MessageName:key down
Message:256
Time:6376015
Window:66926
WindowName:淘宝网 - 淘我喜欢! - Windows Internet Explorer
Ascii_code: 103
Ascii_char:g
Key:G
--------------------Keyboard End--------------------
--------------------MouseEvent Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:01
MessageName:mouse move
Message:512
Time_sec:6376078
Window:132584
WindowName:None
Position:(724, 344)
--------------------MouseEvent End--------------------
--------------------MouseEvent Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:01
MessageName:mouse move
Message:512
Time_sec:6376109
Window:132584
WindowName:None
Position:(724, 344)
--------------------MouseEvent End--------------------
--------------------Keyboard Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:01
MessageName:key down
Message:256
Time:6376625
Window:66926
WindowName:淘宝网 - 淘我喜欢! - Windows Internet Explorer
Ascii_code: 111
Ascii_char:o
Key:O
--------------------Keyboard End--------------------
--------------------Keyboard Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:02
MessageName:key down
Message:256
Time:6376781
Window:66926
WindowName:淘宝网 - 淘我喜欢! - Windows Internet Explorer
Ascii_code: 111
Ascii_char:o
Key:O
--------------------Keyboard End--------------------
--------------------Keyboard Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:02
MessageName:key down
Message:256
Time:6377000
Window:66926
WindowName:淘宝网 - 淘我喜欢! - Windows Internet Explorer
Ascii_code: 103
Ascii_char:g
Key:G
--------------------Keyboard End--------------------
--------------------Keyboard Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:02
MessageName:key down
Message:256
Time:6377140
Window:66926
WindowName:淘宝网 - 淘我喜欢! - Windows Internet Explorer
Ascii_code: 108
Ascii_char:l
Key:L
--------------------Keyboard End--------------------
--------------------Keyboard Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:02
MessageName:key down
Message:256
Time:6377187
Window:66926
WindowName:淘宝网 - 淘我喜欢! - Windows Internet Explorer
Ascii_code: 101
Ascii_char:e
Key:E
--------------------Keyboard End--------------------
--------------------MouseEvent Begin--------------------
Current Time:Thu, 01 Mar 2012 15:07:07
MessageName:mouse move
Message:512
Time_sec:6382093
Window:132584
WindowName:None
Position:(725, 344)
--------------------MouseEvent End--------------------
附:
ASCII(American Standard Code for Information Interchange,美国信息互换标准代码,ASCⅡ)是基于拉丁字母的一套电脑编码系统。它主要用于显示现代英语和其他西欧语言。它是现今最通用的单字节编码系统,并等同于国际标准ISO/IEC 646。
ASCII第一次以规范标准的型态发表是在1967年,最后一次更新则是在1986年,至今为止共定义了128个字符,其中33个字符无法显示(这是以现今操作系统为依归,但在DOS模式下可显示出一些诸如笑脸、扑克牌花式等8-bit符号),且这33个字符多数都已是陈废的控制字符,控制字符的用途主要是用来操控已经处理过的文字,在33个字符之外的是95个可显示的字符,包含用键盘敲下空白键所产生的空白字符也算1个可显示字符(显示为空白)。
二进制 | 十进制 | 十六进制 | 缩写 | 可以显示的表示法 | 名称/意义 |
---|---|---|---|---|---|
0000 0000 | 0 | 00 | NUL | ␀ | 空字符(Null) |
0000 0001 | 1 | 01 | SOH | ␁ | 标题开始 |
0000 0010 | 2 | 02 | STX | ␂ | 本文开始 |
0000 0011 | 3 | 03 | ETX | ␃ | 本文结束 |
0000 0100 | 4 | 04 | EOT | ␄ | 传输结束 |
0000 0101 | 5 | 05 | ENQ | ␅ | 请求 |
0000 0110 | 6 | 06 | ACK | ␆ | 确认回应 |
0000 0111 | 7 | 07 | BEL | ␇ | 响铃 |
0000 1000 | 8 | 08 | BS | ␈ | 退格 |
0000 1001 | 9 | 09 | HT | ␉ | 水平定位符号 |
0000 1010 | 10 | 0A | LF | ␊ | 换行键 |
0000 1011 | 11 | 0B | VT | ␋ | 垂直定位符号 |
0000 1100 | 12 | 0C | FF | ␌ | 换页键 |
0000 1101 | 13 | 0D | CR | ␍ | 归位键 |
0000 1110 | 14 | 0E | SO | ␎ | 取消变换(Shift out) |
0000 1111 | 15 | 0F | SI | ␏ | 启用变换(Shift in) |
0001 0000 | 16 | 10 | DLE | ␐ | 跳出数据通讯 |
0001 0001 | 17 | 11 | DC1 | ␑ | 设备控制一(XON 启用软件速度控制) |
0001 0010 | 18 | 12 | DC2 | ␒ | 设备控制二 |
0001 0011 | 19 | 13 | DC3 | ␓ | 设备控制三(XOFF 停用软件速度控制) |
0001 0100 | 20 | 14 | DC4 | ␔ | 设备控制四 |
0001 0101 | 21 | 15 | NAK | ␕ | 确认失败回应 |
0001 0110 | 22 | 16 | SYN | ␖ | 同步用暂停 |
0001 0111 | 23 | 17 | ETB | ␗ | 区块传输结束 |
0001 1000 | 24 | 18 | CAN | ␘ | 取消 |
0001 1001 | 25 | 19 | EM | ␙ | 连接介质中断 |
0001 1010 | 26 | 1A | SUB | ␚ | 替换 |
0001 1011 | 27 | 1B | ESC | ␛ | 跳出 |
0001 1100 | 28 | 1C | FS | ␜ | 文件分割符 |
0001 1101 | 29 | 1D | GS | ␝ | 组群分隔符 |
0001 1110 | 30 | 1E | RS | ␞ | 记录分隔符 |
0001 1111 | 31 | 1F | US | ␟ | 单元分隔符 |
0111 1111 | 127 | 7F | DEL | ␡ | 删除 |
|
|
|
上一篇: python写报警程序中的声音实现win
下一篇: 用python做oj上的简单题(持续更新
48710
47733
38516
35714
30153
26890
25908
20762
20522
18919
310°
378°
417°
426°
413°
422°
468°
530°
656°
660°