Skip to content

Commit

Permalink
settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Attt committed Sep 5, 2019
1 parent 64e6939 commit 1f7e215
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
96 changes: 50 additions & 46 deletions anti-afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,47 @@ def setWowForeground(self):
return hwnd

class AntiAfk:
logoutShortcutAscii = 0x31
logoutGap = 540
needChangeCharacter = 'y'
wowWindow = WowWindow()
def killTime(self):
self.wowWindow.setWowForeground()
buttonList = [0x58, 0x20]
random.shuffle(buttonList)
for btn in buttonList:
win32api.keybd_event(btn,0,0,0)
time.sleep(random.randint(1, 2))
win32api.keybd_event(btn,0,win32con.KEYEVENTF_KEYUP,0)
# press 'SPACE'
win32api.keybd_event(0x20,0,0,0)
time.sleep(random.randint(1, 2))
win32api.keybd_event(0x20,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(random.randint(4, 5))

def clickMenu(self,x, y):
#set position
win32api.SetCursorPos((x, y))
#left click
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN |
win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)

def logOut(self, top, bottom, right, left):
centerX = (right + left) / 2
centerY = (bottom + top) / 2
height = bottom - top
width = right - left
print('log out, now height is',height,'width is',width,',center point is (', centerX, centerY, ')')
factor = 0.088
if height < 400:
factor = 0.10
downOff = height * factor
self.wowWindow.setWowForeground()
#ESC
win32api.keybd_event(0x1B,0,0,0)
win32api.keybd_event(0x1B,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(0.5)
self.clickMenu(int(centerX),int(centerY + downOff))

# put macro '/logout' in '1'
# run macro '/logout'
def logOutUsingCommand(self):
self.wowWindow.setWowForeground()
print('log out using /logout')
win32api.keybd_event(0x31,0,0,0)
win32api.keybd_event(0x31,0,win32con.KEYEVENTF_KEYUP,0)
win32api.keybd_event(self.logoutShortcutAscii,0,0,0)
win32api.keybd_event(self.logoutShortcutAscii,0,win32con.KEYEVENTF_KEYUP,0)

def changeAnotherCharacter(self):
# press 'down'
self.wowWindow.setWowForeground()
print('change another character')
win32api.keybd_event(0x28,0,0,0)
win32api.keybd_event(0x28,0,win32con.KEYEVENTF_KEYUP,0)

def logIn(self):
# press 'enter'
self.wowWindow.setWowForeground()
print('log in')
win32api.keybd_event(0x0d,0,0,0)
win32api.keybd_event(0x0d,0,win32con.KEYEVENTF_KEYUP,0)

def antiAfk(self):
# get window hanlder and set forground
hwnd = self.wowWindow.setWowForeground()
# get window edge offsets
left, top, right, bottom = win32gui.GetWindowRect(hwnd)

print('window offsets are changed to', left, top, right, bottom)
centerX = (right + left) / 2
centerY = (bottom + top) / 2
print('center point is (', centerX, centerY, ')')

self.wowWindow.setWowForeground()
time.sleep(0.5)

print('kill time...')
i = 0
while i < 90:
# calculate looping times
t = int(self.logoutGap / 6)
while i < t:
self.killTime()
i = i + 1

Expand All @@ -101,7 +69,8 @@ def antiAfk(self):
time.sleep(random.randint(30, 35))

# change character
self.changeAnotherCharacter()
if self.needChangeCharacter == 'y':
self.changeAnotherCharacter()

#take a break
time.sleep(1)
Expand All @@ -112,7 +81,42 @@ def antiAfk(self):
# waiting for log in
time.sleep(10)

def printSettings(self):
print("当前默认设置为:")
print("->>\t是否需要切换角色:", '是' if self.needChangeCharacter =='y' else '否')
print("->>\tlogout宏的快捷键为:", chr(self.logoutShortcutAscii))
print("->>\t小退的间隔时间大约为:", self.logoutGap, '秒')
print("")

def settings(self):
self.printSettings()
reSetting = input("是否需要重新设置?(y/n):")

if reSetting == 'y':
print("")
self.needChangeCharacter = input("是否需要切换角色?(y/n):")
c = '\b单角色模式'
if self.needChangeCharacter == 'y':
c = '\b多角色模式'
print('->>设置为',c)
print("")

sc = input("logout宏的快捷键为:")
self.logoutShortcutAscii = ord(sc)
print('->>快捷键设置为', sc)
print("")

self.logoutGap = int(input("小退的间隔时间大约需要设置为(秒):"))
if self.logoutGap < 6:
self.logoutGap = 6
print("")
print('间隔时间设置为', self.logoutGap)
print("")
self.printSettings()
print('->>设置完成,准备开始...')

def invoke(self):
self.settings()
while True:
self.antiAfk()

Expand Down
1 change: 1 addition & 0 deletions anti-afk_mc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## DeprecationWarning
import win32api,win32con,win32gui
import time,random

Expand Down

0 comments on commit 1f7e215

Please sign in to comment.