展开全部
我觉得不是时间戳(或者说,不是通常意义下的时间戳)。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())
就可以打印消息发生时的年月日时分秒了。