蔭信息安全新IAM試圖教我自己如何建立與Python簡單的鍵盤記錄,我發現這個代碼在一個網站:有沒有辦法在不傳遞參數的情況下調用函數?
import pythoncom, pyHook
def OnKeyboardEvent(event):
print 'MessageName:',event.MessageName
print 'Message:',event.Message
print 'Time:',event.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 mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
,雖然我試圖理解這個代碼,我發現功能「OnKeyboardEvent」的不給調用它的參數
hm.KeyDown = OnKeyboardEvent
所以我的問題是: 有沒有在Python的方式來調用一個函數,而不給它的參數?
'hm.KeyDown = OnKeyboardEvent'不是函數調用。檢查[this](https://stackoverflow.com/questions/10354163/assigning-a-function-to-a-variable)出 – jacoblaw
@jacoblaw非常感謝 –