# to monitor keyboard
The import pythoncom
The import PyHook3
The import win32clipboard
The import of OS, sys
Print (" keyboard after press the key combination Ctrl + M, the contents of the clipboard in can save to a local file ")
Path=OS. Getcwd ()
File_save=path + OS. Path. Sep + "the rid_device_info_keyboard. TXT"
Def OnKeyboardEvent (event) :
# test for a conventional keystroke key (or key combination, etc.)
If the event. The Ascii & gt; 32 and the event. The Ascii & lt; 127:
Print (event. Key)
The else:
# if it is found that the keyboard press the key combination & lt; Ctrl + M> Events, just keep the clipboard contents to the local file
If the event. The Key=="M" :
Win32clipboard. OpenClipboard ()
Paste_value=(https://bbs.csdn.net/topics/win32clipboard.GetClipboardData)
Win32clipboard. CloseClipboard ()
Print ()
Print (" clipboard content has been saved to the file "+ file_save)
Print (" - "* 32)
Print (paste_value)
Print (" - "* 32)
Print ()
With the open (file_save, "a") as f:
Paste_value f.w ritelines (" \ n "+ +" \ n ")
# cycle to monitor the next keystroke events
Return True
# create and register the hooks manager
Kl=PyHook3. HookManager () #
Kl. KeyDown=OnKeyboardEvent
# registered hook and execute
Kl. HookKeyboard ()
Pythoncom. PumpMessages ()
CodePudding user response:
Didn't know what you mean, hooks don't need a DLL encapsulationCodePudding user response: