Created
October 8, 2012 19:06
-
-
Save shalakhin/3854275 to your computer and use it in GitHub Desktop.
Bot prevents character to be dropped out for inactivity sending keyboard "SPACE" command in a random intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from time import sleep | |
from random import randrange | |
try: | |
import win32api | |
import win32con | |
import win32gui | |
except Exception, e: | |
print(e) | |
raw_input('-->') | |
##### Settings #### | |
INTERVAL_FROM = 80 # seconds | |
INTERVAL_TILL = 160 # seconds | |
################### | |
def random_wait(): | |
""" | |
Wait seconds till next event | |
""" | |
return randrange(INTERVAL_FROM, INTERVAL_TILL) | |
def press_space(): | |
""" | |
Send "space" to the current application | |
""" | |
try: | |
print("Bot initiated...") | |
while True: | |
# get hwnd for Wow-64.exe which is 'World of Warcraft' | |
hwnd = win32gui.FindWindow(None, 'World of Warcraft') | |
print hwnd | |
if hwnd == 0: | |
print("Process not found...") | |
else: | |
interval = random_wait() | |
print("Space keypress event in %s seconds..." % interval) | |
sleep(interval) | |
win32api.SendMessage( | |
hwnd, win32con.WM_KEYDOWN, win32con.VK_SPACE, 0 | |
) | |
sleep(1) | |
win32api.SendMessage( | |
hwnd, win32con.WM_KEYUP, win32con.VK_SPACE, 0 | |
) | |
print("Space pressed...") | |
except Exception, e: | |
print(e) | |
raw_input('--> ') | |
press_space() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment