Home > OS >  Global keyboard monitor based on pyhook under Windows
Global keyboard monitor based on pyhook under Windows

Time:09-17

Global keyboard hook need to dynamic link library of encapsulation, but those statements in the program below to show the dynamic link library encapsulation hook? If not, then how to write a program to encapsulate
# 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 encapsulation

CodePudding user response:

reference 1st floor WQR1994 response:
didn't know what you mean, hooks don't need a DLL encapsulation

System hook is not need a dynamic link library of encapsulation?

CodePudding user response:

reference 1st floor WQR1994 response:
didn't know what you mean, hooks don't need a DLL encapsulation

Hooks, and the system can be divided into the thread hook hook monitor event messages of the specified thread, thread hook hook system monitoring system all threads in the event message, because the system hook affects all applications in the system, so the hook function must be on separate dynamic link library (DLL),

CodePudding user response:

Is that so? According to my knowledge system hook don't have to

CodePudding user response:

Do you want to go to see the pyhook source
https://sourceforge.net/p/pyhook/code/ci/master/tree/cpyHook.i
  • Related