Using Python to monitor and simulate mouse keyboard events

Source: Internet
Author: User

Recently watch professional athletes suspected to open the event is very lively, in the next piece of cake, and can not be seen from the video clues. Read some of the discussion about the plug, automatic burst and pressure gun only need to make some changes on the mouse driver, self-aiming or other advanced functions need to read memory or modify game files, detection is easier.

Soldiers 76 long press left button to shoot 4 bullets after the crosshair will be a small range of random floating, so I want to implement a long press left button to automatically burst program.

Only for testing use, despise all plug-ins, playing games is good fun.

Select a library to use with Python Pyhook,pywin32

Pyhook's Documentation: http://pyhook.sourceforge.net/doc_1.5.0/

Then follow the documentation to write it, the code is as follows

1 #Coding:utf-82 3 Importpythoncom4 ImportPyhook5 ImportWin32API6 ImportWin32con7 Import Time8 ImportThreading9 ImportRandomTen  One defSend_click (): A     GlobalDown_num,up_num -      while(1): -         ifdown_num!=Up_num: the win32api.mouse_event (Win32con. Mouseeventf_leftdown, 0, 0, 0, 0) -             #How many seconds, about 0.1 seconds for a shot. -Time.sleep (Random.uniform (0.38,0.42)) - win32api.mouse_event (Win32con. Mouseeventf_leftup, 0, 0, 0, 0) +             #the pause time between bursts -Time.sleep (Random.uniform (0.25,0.29)) +             Print 'Click OK' A          at defOnmouse_leftdown (event): -     #Monitor the left mouse button press event -     GlobalDown_num -Down_num + = 1 -     Print " left Down"+Str (down_num) -     returnTrue in     #returns True to respond to this event, false to indicate interception -  to defOnmouse_leftup (event): +     #Monitor the left mouse button to bounce events -     GlobalUp_num theUp_num + = 1 *     Print " left up up"+Str (up_num) $     returnTruePanax Notoginseng  - defMain (): theHM =Pyhook.hookmanager () +  AHm. Mouseleftdown =Onmouse_leftdown theHm. Mouseleftup =Onmouse_leftup +      - hm. Hookmouse () $      $     #into the loop, if not manually closed, the program will always be in the listening state - pythoncom. Pumpmessages () -  the if __name__=="__main__": -Down_num =0WuyiUp_num =0 the     #code executed by the new thread: -     Print('thread%s is running ...'%Threading.current_thread (). Name) Wut = Threading. Thread (Target=send_click, name='Sendthread') - T.start () About     #T.join () $Main ()

The effect is out, but there is no egg to use.

Using Python to monitor and simulate mouse keyboard events

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.