[Python Study Notes] for keyboard control and monitoring

Source: Internet
Author: User

"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> Keyboard control .py>> Author: Liu Yang>> e-mail: [email protected]>> blog: Www.cnblogs.com/liu66blog "" " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "." "" "" "" "" "" "" "" "" "" "" "" "" #!/usr/bin/env python#-*-.        Coding:utf-8-*-import sys, osfrom pynput.keyboard import controller,key,listener# Monitor Press def on_press (Key): try: Print ("Pressing:", Format (Key.char)) except Attributeerror:print ("pressing:", Format (key)) # Listener release def on_release (key): P Rint ("Already released:", Format (key)) if Key==key.esc: # Stop monitoring return false# start monitoring Def start_listen (): With Listener ( On_press=on_press,on_release=on_release) as Listener:listener.join () if __name__ = = ' __main__ ': # Instantiate keyboard Kb=co Ntroller () # Use the keyboard to enter a letter kb.press (' a ') kb.release (' a ') # using the keyboard input string, note that the current keyboard is tuned into English kb.type ("Hello World") # using    Key.xxx input kb.press (key.space) # Start listening, press ESC to exit the listenerStart_listen () 

[Python Study Notes] for keyboard control and monitoring

Related Article

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.