Advertisement
HNKYTNK

Autoclick Attatched to Window

Apr 27th, 2020
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.15 KB | None | 0 0
  1. import pyautogui
  2. import win32api, win32con, win32gui, win32ui, win32service, os, time
  3. import wmi
  4. import ctypes, sys
  5. import time
  6.  
  7. #Check for admin privileges
  8. def is_admin():
  9.     try:
  10.         return ctypes.windll.shell32.IsUserAnAdmin()
  11.     except:
  12.         return False
  13.  
  14. def f_click(pycwnd):
  15.     x=300
  16.     y=300
  17.     lParam = y <<15 | x
  18.     pycwnd.SendMessage(win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0), lParam);
  19.     pycwnd.SendMessage(win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0), lParam);
  20.    
  21.  
  22.  
  23. def get_whndl():
  24.     #whndl = win32gui.FindWindowEx(0, 0, None, 'ModernWarfare.exe')
  25.     whndl = win32gui.FindWindowEx(0, 0, None, 'mspaint.exe')
  26.     print("ModernWarfare.exe found\n")
  27.     print (whndl)
  28.     return whndl
  29.  
  30. def make_pycwnd(hwnd):      
  31.     PyCWnd = win32ui.CreateWindowFromHandle(hwnd)
  32.     print(PyCWnd, hwnd)
  33.     return PyCWnd
  34.  
  35. def send_input_hax(pycwnd, msg):
  36.     f_click(pycwnd)
  37.     for c in msg:
  38.         if c == "\n":
  39.             pycwnd.SendMessage(win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
  40.             pycwnd.SendMessage(win32con.WM_KEYUP, win32con.VK_RETURN, 0)
  41.             print("Enter Pressed")
  42.         else:
  43.             pycwnd.SendMessage(win32con.WM_CHAR, ord(c), 0)
  44.     pycwnd.UpdateWindow()
  45.  
  46. whndl = get_whndl()
  47.  
  48. def callback(hwnd, hwnds):
  49.     if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
  50.         hwnds[win32gui.GetClassName(hwnd)] = hwnd
  51.     return True
  52.  
  53. if is_admin():
  54.     pass
  55. else:
  56.     ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
  57. print("Wating")    
  58. time.sleep(5)
  59. print("Wait done!")    
  60.  
  61. hwnds = {}
  62. win32gui.EnumChildWindows(whndl, callback, hwnds)
  63. #whndl = hwnds['IW8']
  64. whndl = hwnds['MSPaintApp']
  65.  
  66. pycwnd = make_pycwnd(whndl)
  67. msg = "It works !\n"
  68. send_input_hax(pycwnd,msg)
  69.  
  70. ############################
  71. #Show current active windows
  72. ############################
  73. #print(hwnds)
  74.  
  75. ##############################
  76. #Show current active processes
  77. ##############################
  78. #c = wmi.WMI ()
  79. #for process in c.Win32_Process ():
  80. #    print (process.ProcessId, process.Name)
  81.  
  82. print("\nDone")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement