Last active
June 9, 2017 00:06
-
-
Save Au1st3in/1ad0084cd5c9f53e4d70f5f4142951f3 to your computer and use it in GitHub Desktop.
DayZ AutoRun Python Script with NumLock Toggle
This file contains hidden or 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
import ctypes, time, win32api, win32gui | |
user32, SendInput = ctypes.WinDLL('user32', use_last_error=True), ctypes.windll.user32.SendInput | |
# community.bistudio.com/wiki/DIK_KeyCodes | |
DIK_W = 0x11 | |
DIK_LSHIFT = 0x2A | |
# msdn.microsoft.com/en-us/library/dd375731 | |
VK_NUMLOCK = 0x90 | |
# c struct redefinitions | |
PUL = ctypes.POINTER(ctypes.c_ulong) | |
class KeyBdInput(ctypes.Structure): | |
_fields_ = [("wVk", ctypes.c_ushort), ("wScan", ctypes.c_ushort), ("dwFlags", ctypes.c_ulong), ("time", ctypes.c_ulong), ("dwExtraInfo", PUL)] | |
class HardwareInput(ctypes.Structure): | |
_fields_ = [("uMsg", ctypes.c_ulong), ("wParamL", ctypes.c_short), ("wParamH", ctypes.c_ushort)] | |
class MouseInput(ctypes.Structure): | |
_fields_ = [("dx", ctypes.c_long), ("dy", ctypes.c_long), ("mouseData", ctypes.c_ulong), ("dwFlags", ctypes.c_ulong), ("time",ctypes.c_ulong), ("dwExtraInfo", PUL)] | |
class Input_I(ctypes.Union): | |
_fields_ = [("ki", KeyBdInput), ("mi", MouseInput), ("hi", HardwareInput)] | |
class Input(ctypes.Structure): | |
_fields_ = [("type", ctypes.c_ulong), ("ii", Input_I)] | |
# functions | |
def key_state(VK_CODE): | |
return bool(user32.GetKeyState(VK_CODE)) | |
def toggle_state(*args): | |
for VK_CODE in args: | |
if key_state(VK_CODE): | |
win32api.keybd_event(VK_CODE,0,0,0) | |
def active_window(window_name): | |
window = win32gui.GetForegroundWindow() | |
if str(win32gui.GetWindowText(window)) == window_name: | |
return True | |
return False | |
def find_window(window_name): | |
if win32gui.FindWindow(None, window_name): | |
return True | |
return False | |
def press(*args): | |
for DIK_CODE in args: | |
extra = ctypes.c_ulong(0) | |
ii_ = Input_I() | |
ii_.ki = KeyBdInput(0, DIK_CODE, 0x0008, 0, ctypes.pointer(extra)) | |
x = Input(ctypes.c_ulong(1), ii_) | |
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x)) | |
def release(*args): | |
for DIK_CODE in args[::-1]: | |
extra = ctypes.c_ulong(0) | |
ii_ = Input_I() | |
ii_.ki = KeyBdInput(0, DIK_CODE, 0x0008 | 0x0002, 0, ctypes.pointer(extra)) | |
x = Input(ctypes.c_ulong(1), ii_) | |
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x)) | |
def hold(*args): | |
press(*args) | |
time.sleep(.05) | |
release(*args) | |
# main | |
if __name__ == "__main__": | |
toggle_state(VK_NUMLOCK) | |
while True: | |
if not find_window('DayZ'): | |
toggle_state(VK_NUMLOCK) | |
break | |
elif key_state(VK_NUMLOCK) and active_window('DayZ'): | |
hold(DIK_LSHIFT, DIK_W) | |
else: | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment