python pyhook_python使用pyHook.HookManager()返回来的event中,event.Time怎么转换成为datetime形式?...
展开全部
我觉得不是时间戳(或者说,不是通常意义下的时间戳)。e69da5e887aa3231313335323631343130323136353331333335303437
这里的event可能是KeyboardEvent或 MouseEvent(视钩子类型而定)。而这两个类又都是HookEvent的子类。
HookEvent有如下几个成员:
Message: Keyboard or mouse event message
Time: Seconds since the epoch when the even current
Window: Window handle of the foreground window at the time of the event
WindowName: Name of the foreground window at the time of the event
这里,对Time成员的描述是:
Seconds since the epoch when the even current
这里的epoch很有意思。
一般上,我们在使用Python中的time模块,或者C标准库中的time.h时,认为epoch是(摘自Python2.7 time模块的文档):
The epoch is the point where the time starts. On January 1st of that year, at 0 hours, the “time since the epoch” is zero. For Unix, the epoch is 1970.
但是,这里的epoch却不是。看下面一段改编自pyhook官网的小例子:# -*- coding: utf-8 -*-
import pythoncom, pyHook
import win32api
import time
def OnKeyboardEvent(event):
print event.Time
# Return the time in seconds since the epoch as a floating point number.
#
# The epoch is the point where the time starts. On January 1st of that year,
# at 0 hours, the “time since the epoch” is zero. For Unix, the epoch is 1970.
print time.time()
# Returns the number of milliseconds since windows started
print win32api.GetTickCount()
print 'MessageName:',event.MessageName
print 'Message:',event.Message
print 'Time:', time.ctime(time.time())
print 'Window:',event.Window
print 'WindowName:',event.WindowName
print 'Ascii:', event.Ascii, chr(event.Ascii)
print 'Key:', event.Key
print 'KeyID:', event.KeyID
print 'ScanCode:', event.ScanCode
print 'Extended:', event.Extended
print 'Injected:', event.Injected
print 'Alt', event.Alt
print 'Transition', event.Transition
print '---'
# return True to pass the event to other handlers
return True
# create a hook manager
hm = pyHook.HookManager()
# watch for all keyboard events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
其中:
print event.Time
print time.time()
print win32api.GetTickCount()
我发现,event.Time和GetTickCount返回的值是一样的。而GetTickCount的含义是:
Returns the number of milliseconds since windows started
也就是,从本次开机到GetTickCount调用时经过的毫秒数。
所以,不能依赖event.Time来获取时间了。而time模块就派上用场了。比如:
print 'Time:', time.ctime(time.time())
就可以打印消息发生时的年月日时分秒了。
python pyhook_python使用pyHook.HookManager()返回来的event中,event.Time怎么转换成为datetime形式?...相关推荐
- python中将HTTP头部中的GMT时间转换成datetime时间格式
原文: https://blog.csdn.net/zoulonglong/article/details/80585716 需求背景:目前在做接口的自动化测试平台,由于接口用例执行后返回的结果中的时 ...
- 【Python】监测鼠标各种事件(左键/中键/右键是否点下)
目录 0. 前言 1. 安装PyHook3 2. 检测鼠标左键/中键/右键是否按下 3. PyHook3详细讲解 0. 前言 最近在写一个脚本,需要用到监测用户是否点击鼠标中键,然后触发相应的功能.这 ...
- python三引号 内部变量_python在三引号中使用变量
1.定义和运算: 变量名 = 值 定义变量举例: # 定义一个变量 myCar = "比亚迪F0" # 输出一个变量 print(myCar) 变量之间的简单运算举例: price ...
- python watchdog 同时检测到多个事件_python中watchdog文件监控与检测上传功能
引言 上一篇介绍完了观察者模式的原理,本篇想就此再介绍一个小应用,虽然我也就玩了一下午,是当时看observer正好找到的,以及还有Django-observer,但Django很久没用了,所以提下这 ...
- python自带的sum()函数和numpy库中的sum()函数的区别
在学习<机器学习实战>一书的第十章时,对 return np.sqrt(sum(np.power(vecA - vecB, 2))) 这样一条语句输出的结果老是不对,明明想要输出的是对两个 ...
- python批量读取文件名_python - 从路径中提取文件名,无论os / path形式如何
python - 从路径中提取文件名,无论os / path形式如何 无论操作系统或路径格式是什么,我可以使用哪个Python库从路径中提取文件名? 例如,我想要所有这些路径返回c: a/b/c/ a ...
- bat脚本中获取上级目录_使用Python写一个可以监控Tomcat 运行的脚本,并且把.py文件转换成.exe文件...
使用Python写一个可以监控Tomcat 运行的脚本,并且把.py文件转换成.exe文件 文章来源与博主本人的CSDN博客,博客地址:https://blog.csdn.net/weixin_435 ...
- java执行python脚本_使用Runtime.getRuntime().exec()在java中调用python脚本
举例有一个Python脚本叫test.py,现在想要在Java里调用这个脚本.假定这个test.py里面使用了拓展的包,使得pythoninterpreter之类内嵌的编译器无法使用,那么只能采用ja ...
- python 数据框缺失值_Python:处理数据框中的缺失值
python 数据框缺失值 介绍 (Introduction) In the last article we went through on how to find the missing value ...
- 手机上python编程工具3和3h有区别吗_Python3.5内置模块之time与datetime模块用法实例分析...
本文实例讲述了Python3.5内置模块之time与datetime模块用法.分享给大家供大家参考,具体如下: 1.模块的分类 a.标准库(Python自带):sys.os模块 b.开源模块(第三方模 ...
最新文章
- python怎么导入时间-python初步学习-import和datetime模块
- 【计算机网络】网络层 : 网络层设备 ( 路由器 | 输入端口处理 | 输出端口处理 | 物理层、数据链路层、网络层 设备对比 | 路由表 与 路由转发 )
- java基础-Eclipse开发工具介绍
- C++与C#混合编程
- 是否应该饮用酵素和自制的葡萄酒
- 2020非全日计算机博士,在职攻读博士是不是非常难,免考在职博士和非全日博士有什么不同...
- C++之运算符重载(前置++和后置++)
- 每周学算法/读英文/知识点心得分享 3.4 - 3.8
- HashMap学习之transient
- VS2012下基于Glut OpenGL GL_POLYGON_STIPPLE示例程序:
- Ros代码迁移,编译头文件报错解决办法
- POJ 2686 Traveling by Stagecoach 壮压DP
- cpu型号怎么看服务器,看不懂CPU?学会看CPU只要五分钟
- 【pytorch图像分类】AlexNet网络结构
- c51单片机扩展64K的RAM
- Maya Xgen交互式毛发的导出导入,用于其他项目
- 网站服务器拥挤如何进去,教你一招:有效解决网络拥挤的办法!
- 低代码里程碑版—JeecgBoot 3.4.3 版本发布,低代码功能专项升级
- 区间类动态规划(dp)
- windows7 专业版安装中文语言包