Python hook listening event and pythonhook listening

Source: Internet
Author: User

Python hook listening event and pythonhook listening

Python hook listening event

Author: vpoet

Date: Summer

#-*-Coding: UTF-8-*-# by oldj http://oldj.net/# import pythoncom import pyHook def onMouseEvent (event): # Listen to mouse event print "MessageName:", event. messageName print "Message:", event. message print "Time:", event. time print "Window:", event. window print "WindowName:", event. windowName print "Position:", event. position print "Wheel:", event. wheel print "Injected:", event. injected print "---" # Return True to pass the event to another handler # Note: if False is returned here, the mouse event is intercepted. # That is to say, your mouse seems to be frozen. It seems that you have lost the response. return True def onKeyboardEvent (event): # Listen to the keyboard 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 def main (): # create a "Hook" management object hm = pyHook. hookManager () # Listen to all Keyboard Events hm. keyDown = onKeyboardEvent # Set the keyboard "hook" hm. hookKeyboard () # Listen to all mouse events hm. mouseAll = onMouseEvent # Set the mouse "Hook" hm. hookMouse () # enters the loop. If you do not close it manually, the program will remain in the listening status pythoncom. pumpMessages () if _ name _ = "_ main _": main ()



Run:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.