Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import autopy
- import pyautogui
- import os
- import sys
- import win32api
- import win32gui
- import win32ui
- import win32con
- import ctypes
- import time
- import thread
- import Image
- import subprocess
- from smtplib import SMTP as SMTP
- from os.path import basename
- from email.mime.text import MIMEText
- from email.MIMEMultipart import MIMEMultipart
- from email.mime.application import MIMEApplication
- from email.MIMEBase import MIMEBase
- from email import Encoders
- from functools import reduce
- from ctypes import windll, Structure, c_ulong, byref, wintypes
- byref = ctypes.byref
- user32 = ctypes.windll.user32
- emailFromUsername="email"
- emailToUsername=['email']
- emailPassword="NOPE"
- emailServer="smtp.gmail.com"
- screenshotbmp="C:\Users\Jeremy\Desktop\screenshot.bmp"
- screenShotLocation="C:\Users\Jeremy\Desktop\screenshot.jpg"
- check_x=2362
- check_y=1224
- check_c="0x3367ae"
- enable_run = 0
- HOTKEYS = {
- 1 : (win32con.VK_F2, win32con.MOD_WIN),
- 2 : (win32con.VK_F3, win32con.MOD_WIN),
- 3 : (win32con.VK_F4, win32con.MOD_WIN),
- 4 : (win32con.VK_F12, win32con.MOD_WIN)
- }
- def takeScreenShot():
- hwin = win32gui.GetDesktopWindow()
- width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
- height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
- left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
- top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)
- hwindc = win32gui.GetWindowDC(hwin)
- srcdc = win32ui.CreateDCFromHandle(hwindc)
- memdc = srcdc.CreateCompatibleDC()
- bmp = win32ui.CreateBitmap()
- bmp.CreateCompatibleBitmap(srcdc, width, height)
- memdc.SelectObject(bmp)
- memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
- bmp.SaveBitmapFile(memdc, screenshotbmp)
- im = Image.open(screenshotbmp)
- im.save(screenShotLocation, "JPEG")
- def emailScreenShot():
- send_mail(emailFromUsername, emailToUsername,"AutoBot","Screenshot Attached", screenShotLocation, emailServer)
- def send_mail(send_from, send_to, subject, text, files=None,
- server="127.0.0.1"):
- assert isinstance(send_to, list)
- msg = MIMEMultipart()
- msg['From'] = send_from
- msg['To'] = send_to[0]
- msg['Subject'] = subject
- msg.attach(MIMEText(text))
- with open(files, "rb") as fil:
- part = MIMEApplication(
- fil.read(),
- Name=basename(files)
- )
- part['Content-Disposition'] = 'attachment; filename="%s"' % basename(files)
- msg.attach(part)
- conn = SMTP(host=server, port=587)
- conn.set_debuglevel(1)
- conn.ehlo()
- conn.starttls()
- conn.ehlo()
- conn.login(emailFromUsername,emailPassword)
- conn.sendmail(send_from, send_to, msg.as_string())
- conn.close()
- class POINT(Structure):
- _fields_ = [("x", c_ulong), ("y", c_ulong)]
- def queryMousePosition():
- pt = POINT()
- windll.user32.GetCursorPos(byref(pt))
- return { "x": pt.x, "y": pt.y}
- def exec_win_f2 ():
- #XY = queryMousePosition()
- global check_x
- #check_x = XY['x']
- global check_y
- #check_y = XY['y']
- global check_c
- check_c=str(hex(autopy.bitmap.capture_screen().get_color(check_x, check_y)))
- check_c=check_c
- print("X:" + str(check_x) + " Y:" + str(check_y) + " Colour:" + check_c)
- def exec_win_f3 ():
- takeScreenShot()
- emailScreenShot()
- def exec_win_f4 ():
- global enable_run
- if enable_run == 1:
- enable_run = 0
- print("Disabled Execution")
- else:
- enable_run = 1
- print("Enabled Execution")
- def exec_win_f12 ():
- print("exit")
- sys.exit()
- HOTKEY_ACTIONS = {
- 1 : exec_win_f2,
- 2 : exec_win_f3,
- 3 : exec_win_f4,
- 4 : exec_win_f12
- }
- def test_for_change ():
- global check_c
- global check_x
- global check_y
- changedtest=hex(autopy.bitmap.capture_screen().get_color(check_x, check_y))
- changedtest=changedtest
- if changedtest != check_c:
- return 0
- print ("appeared" + check_c + " = " + changedtest )
- return 1
- def execution_thread (threadName, delay):
- while True:
- while test_for_change() == 0:
- time.sleep(delay)
- print("Looping")
- takeScreenShot()
- emailScreenShot()
- global enable_run
- exit()
- enable_run=0
- for id, values in HOTKEYS.items ():
- vk, modifiers = values[0], reduce (lambda x, y: x | y, values[1:])
- print ("Registering id", id, "for key", vk)
- if not user32.RegisterHotKey (None, id, modifiers, vk):
- print ("Unable to register id", id)
- try:
- msg = wintypes.MSG ()
- while user32.GetMessageA (byref (msg), None, 0, 0) != 0:
- if msg.message == win32con.WM_HOTKEY:
- action_to_take = HOTKEY_ACTIONS.get (msg.wParam)
- if action_to_take:
- action_to_take ()
- if enable_run == 1:
- try:
- thread.start_new_thread( execution_thread, ("Thread-1", 2, ) )
- except:
- print ("Error: unable to start thread")
- user32.TranslateMessage (byref (msg))
- user32.DispatchMessageA (byref (msg))
- finally:
- for id in HOTKEYS.keys ():
- user32.UnregisterHotKey (None, id)
- print("user32.UnregisterHotKey (None, id)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement