Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shalakhin
Created October 8, 2012 19:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shalakhin/3854275 to your computer and use it in GitHub Desktop.
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
# -*- 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