<s> '''<STR_LIT>''' <EOL> import sys <EOL> import time <EOL> import ctypes <EOL> import multiprocessing <EOL> from ctypes import * <EOL> from ctypes . wintypes import * <EOL> user32 = windll . user32 <EOL> gdi = windll . gdi32 <EOL> kernel32 = windll . kernel32 <EOL> cdll = cdll . msvcrt <EOL> class WIN32CON ( object ) : <EOL> LEFT_DOWN = <NUM_LIT> <EOL> LEFT_UP = <NUM_LIT> <EOL> MIDDLE_DOWN = <NUM_LIT> <EOL> MIDDLE_UP = <NUM_LIT> <EOL> MOVE = <NUM_LIT> <EOL> RIGHT_DOWN = <NUM_LIT> <EOL> RIGHT_UP = <NUM_LIT> <EOL> WHEEL = <NUM_LIT> <EOL> XDOWN = <NUM_LIT> <EOL> XUP = <NUM_LIT> <EOL> HWHEEL = <NUM_LIT> <EOL> win32con = WIN32CON <EOL> class BITMAP ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_short ) , <EOL> ( '<STR_LIT>' , c_short ) , <EOL> ( '<STR_LIT>' , c_void_p ) , <EOL> ] <EOL> class BITMAPFILEHEADER ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , ctypes . c_short ) , <EOL> ( '<STR_LIT>' , ctypes . c_uint32 ) , <EOL> ( '<STR_LIT>' , ctypes . c_short ) , <EOL> ( '<STR_LIT>' , ctypes . c_short ) , <EOL> ( '<STR_LIT>' , ctypes . c_uint32 ) <EOL> ] <EOL> class BITMAPINFOHEADER ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , ctypes . c_uint32 ) , <EOL> ( '<STR_LIT>' , ctypes . c_int ) , <EOL> ( '<STR_LIT>' , ctypes . c_int ) , <EOL> ( '<STR_LIT>' , ctypes . c_short ) , <EOL> ( '<STR_LIT>' , ctypes . c_short ) , <EOL> ( '<STR_LIT>' , ctypes . c_uint32 ) , <EOL> ( '<STR_LIT>' , ctypes . c_uint32 ) , <EOL> ( '<STR_LIT>' , ctypes . c_long ) , <EOL> ( '<STR_LIT>' , ctypes . c_long ) , <EOL> ( '<STR_LIT>' , ctypes . c_uint32 ) , <EOL> ( '<STR_LIT>' , ctypes . c_uint32 ) <EOL> ] <EOL> class BITMAPINFO ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , BITMAPINFOHEADER ) , <EOL> ( '<STR_LIT>' , ctypes . c_ulong * <NUM_LIT:3> ) <EOL> ] <EOL> class MOUSEINPUT ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , LONG ) , <EOL> ( '<STR_LIT>' , LONG ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT:time>' , DWORD ) , <EOL> ( '<STR_LIT>' , POINTER ( ULONG ) ) , <EOL> ] <EOL> class KEYBDINPUT ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , WORD ) , <EOL> ( '<STR_LIT>' , WORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT:time>' , DWORD ) , <EOL> ( '<STR_LIT>' , POINTER ( ULONG ) ) , <EOL> ] <EOL> class HARDWAREINPUT ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , WORD ) , <EOL> ( '<STR_LIT>' , DWORD ) <EOL> ] <EOL> class INPUT ( ctypes . Structure ) : <EOL> class _I ( Union ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , MOUSEINPUT ) , <EOL> ( '<STR_LIT>' , KEYBDINPUT ) , <EOL> ( '<STR_LIT>' , HARDWAREINPUT ) , <EOL> ] <EOL> _anonymous_ = '<STR_LIT:i>' <EOL> _fields_ = [ <EOL> ( '<STR_LIT:type>' , DWORD ) , <EOL> ( '<STR_LIT:i>' , _I ) , <EOL> ] <EOL> class RECT ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT:left>' , c_long ) , <EOL> ( '<STR_LIT>' , c_long ) , <EOL> ( '<STR_LIT:right>' , c_long ) , <EOL> ( '<STR_LIT>' , c_long ) <EOL> ] <EOL> class KeyConsts ( object ) : <EOL> _key_names = [ "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:end>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:0>" , "<STR_LIT:1>" , "<STR_LIT:2>" , "<STR_LIT:3>" , "<STR_LIT:4>" , "<STR_LIT:5>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" , "<STR_LIT:e>" , "<STR_LIT:f>" , "<STR_LIT:g>" , "<STR_LIT:h>" , "<STR_LIT:i>" , "<STR_LIT>" , "<STR_LIT:k>" , "<STR_LIT:l>" , "<STR_LIT:m>" , "<STR_LIT:n>" , "<STR_LIT:o>" , "<STR_LIT:p>" , "<STR_LIT:q>" , "<STR_LIT:r>" , "<STR_LIT:s>" , "<STR_LIT:t>" , "<STR_LIT:u>" , "<STR_LIT:v>" , "<STR_LIT:w>" , "<STR_LIT:x>" , "<STR_LIT:y>" , "<STR_LIT:z>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:;>" , "<STR_LIT:=>" , "<STR_LIT:U+002C>" , "<STR_LIT:->" , "<STR_LIT:.>" , "<STR_LIT:/>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:[>" , "<STR_LIT:\\>" , "<STR_LIT:]>" , "<STR_LIT:'>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> _vk_codes = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> _shifted_keys = '<STR_LIT>' <EOL> _unshifted_keys = "<STR_LIT>" <EOL> special_map = { key : val for ( key , val ) in zip ( _shifted_keys , _unshifted_keys ) } <EOL> key_mapping = { key : code for ( key , code ) in zip ( _key_names , _vk_codes ) } <EOL> class Keys ( object ) : <EOL> space = <NUM_LIT:32> <EOL> left_mouse_button = <NUM_LIT:1> <EOL> right_mouse_button = <NUM_LIT:2> <EOL> control_break_processing = <NUM_LIT:3> <EOL> middle_mouse_button_three_button_mouse = <NUM_LIT:4> <EOL> x1_mouse_button = <NUM_LIT:5> <EOL> x2_mouse_button = <NUM_LIT:6> <EOL> undefined = <NUM_LIT:7> <EOL> backspace = <NUM_LIT:8> <EOL> tab = <NUM_LIT:9> <EOL> reserved = <NUM_LIT:10> <EOL> clear = <NUM_LIT:12> <EOL> enter = <NUM_LIT> <EOL> undefined = <NUM_LIT> <EOL> shift = <NUM_LIT:16> <EOL> ctrl = <NUM_LIT> <EOL> alt = <NUM_LIT> <EOL> pause = <NUM_LIT> ; <EOL> caps_lock = <NUM_LIT:20> <EOL> undefined = <NUM_LIT> <EOL> undefined = <NUM_LIT> <EOL> esc = <NUM_LIT> <EOL> spacebar = <NUM_LIT:32> <EOL> page_up = <NUM_LIT> <EOL> page_down = <NUM_LIT> <EOL> end = <NUM_LIT> <EOL> home = <NUM_LIT> <EOL> left_arrow = <NUM_LIT> <EOL> up_arrow = <NUM_LIT> <EOL> right_arrow = <NUM_LIT> <EOL> down_arrow = <NUM_LIT> <EOL> select = <NUM_LIT> <EOL> print_key = <NUM_LIT> <EOL> execute = <NUM_LIT> <EOL> print_screen = <NUM_LIT> <EOL> ins = <NUM_LIT> <EOL> delete = <NUM_LIT> <EOL> help_key = <NUM_LIT> <EOL> zero = <NUM_LIT> <EOL> one = <NUM_LIT> <EOL> two = <NUM_LIT:50> <EOL> three = <NUM_LIT> <EOL> four = <NUM_LIT> <EOL> five = <NUM_LIT> <EOL> six = <NUM_LIT> <EOL> seven = <NUM_LIT> <EOL> eight = <NUM_LIT> <EOL> nine = <NUM_LIT> <EOL> undefined = <NUM_LIT> <EOL> a = <NUM_LIT> <EOL> b = <NUM_LIT> <EOL> c = <NUM_LIT> <EOL> d = <NUM_LIT> <EOL> e = <NUM_LIT> <EOL> f = <NUM_LIT> <EOL> g = <NUM_LIT> <EOL> h = <NUM_LIT> <EOL> i = <NUM_LIT> <EOL> j = <NUM_LIT> <EOL> k = <NUM_LIT> <EOL> l = <NUM_LIT> <EOL> m = <NUM_LIT> <EOL> n = <NUM_LIT> <EOL> o = <NUM_LIT> <EOL> p = <NUM_LIT> <EOL> q = <NUM_LIT> <EOL> r = <NUM_LIT> <EOL> s = <NUM_LIT> <EOL> t = <NUM_LIT> <EOL> u = <NUM_LIT> <EOL> v = <NUM_LIT> <EOL> w = <NUM_LIT> <EOL> x = <NUM_LIT> <EOL> y = <NUM_LIT> <EOL> z = <NUM_LIT> <EOL> left_windows__natural_board = <NUM_LIT> <EOL> right_windows__natural_board = <NUM_LIT> <EOL> applications__natural_board = <NUM_LIT> <EOL> reserved = <NUM_LIT> <EOL> computer_sleep = <NUM_LIT> <EOL> numeric_pad_0 = <NUM_LIT> <EOL> numeric_pad_1 = <NUM_LIT> <EOL> numeric_pad_2 = <NUM_LIT> <EOL> numeric_pad_3 = <NUM_LIT> <EOL> numeric_pad_4 = <NUM_LIT:100> <EOL> numeric_pad_5 = <NUM_LIT> <EOL> numeric_pad_6 = <NUM_LIT> <EOL> numeric_pad_7 = <NUM_LIT> <EOL> numeric_pad_8 = <NUM_LIT> <EOL> numeric_pad_9 = <NUM_LIT> <EOL> multiply = <NUM_LIT> <EOL> add = <NUM_LIT> <EOL> separator = <NUM_LIT> <EOL> subtract = <NUM_LIT> <EOL> decimal = <NUM_LIT> <EOL> divide = <NUM_LIT> <EOL> f1 = <NUM_LIT> <EOL> f2 = <NUM_LIT> <EOL> f3 = <NUM_LIT> <EOL> f4 = <NUM_LIT> <EOL> f5 = <NUM_LIT> <EOL> f6 = <NUM_LIT> <EOL> f7 = <NUM_LIT> <EOL> f8 = <NUM_LIT> <EOL> f9 = <NUM_LIT> <EOL> f10 = <NUM_LIT> <EOL> f11 = <NUM_LIT> <EOL> f12 = <NUM_LIT> <EOL> f13 = <NUM_LIT> <EOL> f14 = <NUM_LIT> <EOL> f15 = <NUM_LIT> <EOL> f16 = <NUM_LIT> <EOL> f17 = <NUM_LIT> <EOL> f18 = <NUM_LIT> <EOL> f19 = <NUM_LIT> <EOL> f20 = <NUM_LIT> <EOL> f21 = <NUM_LIT> <EOL> f22 = <NUM_LIT> <EOL> f23 = <NUM_LIT> <EOL> f24 = <NUM_LIT> <EOL> unassigned = <NUM_LIT> <EOL> num_lock = <NUM_LIT> <EOL> scroll_lock = <NUM_LIT> <EOL> oem_specific = <NUM_LIT> <EOL> unassigned = <NUM_LIT> <EOL> left_shift = <NUM_LIT> <EOL> right_shift = <NUM_LIT> <EOL> left_control = <NUM_LIT> <EOL> right_control = <NUM_LIT> <EOL> left_menu = <NUM_LIT> <EOL> right_menu = <NUM_LIT> <EOL> browser_back = <NUM_LIT> <EOL> browser_forward = <NUM_LIT> <EOL> browser_refresh = <NUM_LIT> <EOL> browser_stop = <NUM_LIT> <EOL> browser_search = <NUM_LIT> <EOL> browser_favorites = <NUM_LIT> <EOL> browser_start_and_home = <NUM_LIT> <EOL> volume_mute = <NUM_LIT> <EOL> volume_down = <NUM_LIT> <EOL> volume_up = <NUM_LIT> <EOL> next_track = <NUM_LIT> <EOL> previous_track = <NUM_LIT> <EOL> stop_media = <NUM_LIT> <EOL> play_pause_media = <NUM_LIT> <EOL> start_mail = <NUM_LIT> <EOL> select_media = <NUM_LIT> <EOL> start_application_1 = <NUM_LIT> <EOL> start_application_2 = <NUM_LIT> <EOL> reserved = <NUM_LIT> <EOL> semicolon = <NUM_LIT> <EOL> equals = <NUM_LIT> <EOL> comma = <NUM_LIT> <EOL> minus = <NUM_LIT> <EOL> peiod = <NUM_LIT> <EOL> forward_slash = <NUM_LIT> <EOL> back_tick = <NUM_LIT> <EOL> reserved = <NUM_LIT> <EOL> unassigned = <NUM_LIT> <EOL> open_brace = <NUM_LIT> <EOL> backslash = <NUM_LIT> <EOL> close_brace = <NUM_LIT> <EOL> apostrophe = <NUM_LIT> <EOL> reserved = <NUM_LIT> <EOL> oem_specific = <NUM_LIT> <EOL> either_the_angle_bracket__or_the_backslash__on_the_rt_102__board = <NUM_LIT> <EOL> oem_specific = <NUM_LIT> <EOL> oem_specific = <NUM_LIT> <EOL> unassigned = <NUM_LIT> <EOL> oem_specific = <NUM_LIT> <EOL> attn = <NUM_LIT> <EOL> crsel = <NUM_LIT> <EOL> exsel = <NUM_LIT> <EOL> erase_eof = <NUM_LIT> <EOL> play = <NUM_LIT> <EOL> zoom = <NUM_LIT> <EOL> reserved = <NUM_LIT> <EOL> pa1 = <NUM_LIT> <EOL> clear = <NUM_LIT> <EOL> class Robot ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , wname = None ) : <EOL> wname = wname if wname is not None else user32 . GetDesktopWindow ( ) <EOL> try : <EOL> wname . lower ( ) <EOL> hwnd = self . get_window_hwnd ( wname ) <EOL> if hwnd : <EOL> self . hwnd = hwnd <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except AttributeError : <EOL> self . hwnd = wname <EOL> def set_mouse_pos ( self , x , y ) : <EOL> '''<STR_LIT>''' <EOL> wx , wy = self . pos <EOL> user32 . SetCursorPos ( x + wx , y + wy ) <EOL> def get_mouse_pos ( self ) : <EOL> '''<STR_LIT>''' <EOL> coords = pointer ( c_long ( <NUM_LIT:0> ) ) <EOL> user32 . GetCursorPos ( coords ) <EOL> x , y = coords [ <NUM_LIT:0> ] , coords [ <NUM_LIT:1> ] <EOL> wx , wy = self . pos <EOL> return x - wx , y - wy <EOL> def get_pixel ( self , x = None , y = None ) : <EOL> '''<STR_LIT>''' <EOL> if x is None or y is None : <EOL> x , y = self . get_mouse_pos ( ) <EOL> wx , wy = self . pos <EOL> x , y = x + wx , y + wy <EOL> else : <EOL> wx , wy = self . pos <EOL> x , y = wx + x , wy + y <EOL> RGBInt = gdi . GetPixel ( <EOL> user32 . GetDC ( <NUM_LIT:0> ) , <EOL> x , y <EOL> ) <EOL> red = RGBInt & <NUM_LIT:255> <EOL> green = ( RGBInt >> <NUM_LIT:8> ) & <NUM_LIT:255> <EOL> blue = ( RGBInt >> <NUM_LIT:16> ) & <NUM_LIT:255> <EOL> return ( red , green , blue ) <EOL> def mouse_down ( self , button ) : <EOL> '''<STR_LIT>''' <EOL> press_events = { <EOL> '<STR_LIT:left>' : ( win32con . LEFT_DOWN , None , None , None , None ) , <EOL> '<STR_LIT:right>' : ( win32con . RIGHT_DOWN , None , None , None , None ) , <EOL> '<STR_LIT>' : ( win32con . MIDDLE_DOWN , None , None , None , None ) <EOL> } <EOL> user32 . mouse_event ( <EOL> * press_events [ button . lower ( ) ] <EOL> ) <EOL> def mouse_up ( self , button ) : <EOL> '''<STR_LIT>''' <EOL> release_events = { <EOL> '<STR_LIT:left>' : ( win32con . LEFT_UP , None , None , None , None ) , <EOL> '<STR_LIT:right>' : ( win32con . RIGHT_UP , None , None , None , None ) , <EOL> '<STR_LIT>' : ( win32con . MIDDLE_UP , None , None , None , None ) <EOL> } <EOL> user32 . mouse_event ( <EOL> * release_events [ button . lower ( ) ] <EOL> ) <EOL> def click_mouse ( self , button ) : <EOL> '''<STR_LIT>''' <EOL> self . mouse_down ( button ) <EOL> self . mouse_up ( button ) <EOL> def double_click_mouse ( self , button ) : <EOL> '''<STR_LIT>''' <EOL> self . click_mouse ( button ) <EOL> self . sleep ( <NUM_LIT> ) <EOL> self . click_mouse ( button ) <EOL> def move_and_click ( self , x , y , button ) : <EOL> "<STR_LIT>" <EOL> self . set_mouse_pos ( x , y ) <EOL> self . click_mouse ( button ) <EOL> def scroll_mouse_wheel ( self , direction , clicks ) : <EOL> '''<STR_LIT>''' <EOL> for num in range ( clicks ) : <EOL> self . _scrollup ( ) if direction . lower ( ) == '<STR_LIT>' else self . _scrolldown ( ) <EOL> def _scrollup ( self ) : <EOL> user32 . mouse_event ( self . win32con . WHEEL , None , None , <NUM_LIT> , None ) <EOL> def _scrolldown ( self ) : <EOL> user32 . mouse_event ( self . win32con . WHEEL , None , None , - <NUM_LIT> , None ) <EOL> def get_clipboard_data ( self ) : <EOL> '''<STR_LIT>''' <EOL> CF_TEXT = <NUM_LIT:1> <EOL> user32 . OpenClipboard ( None ) <EOL> hglb = user32 . GetClipboardData ( CF_TEXT ) <EOL> text_ptr = c_char_p ( kernel32 . GlobalLock ( hglb ) ) <EOL> kernel32 . GlobalUnlock ( hglb ) <EOL> return text_ptr . value <EOL> def add_to_clipboard ( self , string ) : <EOL> '''<STR_LIT>''' <EOL> GHND = <NUM_LIT> <EOL> hGlobalMemory = kernel32 . GlobalAlloc ( GHND , len ( bytes ( string ) ) + <NUM_LIT:1> ) <EOL> lpGlobalMemory = kernel32 . GlobalLock ( hGlobalMemory ) <EOL> lpGlobalMemory = kernel32 . lstrcpy ( lpGlobalMemory , string ) <EOL> kernel32 . GlobalUnlock ( lpGlobalMemory ) <EOL> user32 . OpenClipboard ( None ) <EOL> user32 . EmptyClipboard ( ) <EOL> hClipMemory = user32 . SetClipboardData ( <NUM_LIT:1> , hGlobalMemory ) <EOL> user32 . CloseClipboard ( ) <EOL> def clear_clipboard ( self ) : <EOL> '''<STR_LIT>''' <EOL> user32 . OpenClipboard ( None ) <EOL> user32 . EmptyClipboard ( ) <EOL> user32 . CloseClipboard ( ) <EOL> def _get_monitor_coordinates ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def take_screenshot ( self , bounds = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> from PIL import Image <EOL> except ImportError as e : <EOL> print ( e ) <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( ) <EOL> return self . _make_image_from_buffer ( self . _get_screen_buffer ( bounds ) ) <EOL> def _get_screen_buffer ( self , bounds = None ) : <EOL> SM_XVIRTUALSCREEN = <NUM_LIT> <EOL> SM_YVIRTUALSCREEN = <NUM_LIT> <EOL> SM_CXVIRTUALSCREEN = <NUM_LIT> <EOL> SM_CYVIRTUALSCREEN = <NUM_LIT> <EOL> hDesktopWnd = user32 . GetDesktopWindow ( ) <EOL> left = user32 . GetSystemMetrics ( SM_XVIRTUALSCREEN ) <EOL> top = user32 . GetSystemMetrics ( SM_YVIRTUALSCREEN ) <EOL> width = user32 . GetSystemMetrics ( SM_CXVIRTUALSCREEN ) <EOL> height = user32 . GetSystemMetrics ( SM_CYVIRTUALSCREEN ) <EOL> if bounds : <EOL> left , top , right , bottom = bounds <EOL> width = right - left <EOL> height = bottom - top <EOL> hDesktopDC = user32 . GetWindowDC ( hDesktopWnd ) <EOL> if not hDesktopDC : print ( '<STR_LIT>' ) ; sys . exit ( ) <EOL> hCaptureDC = gdi . CreateCompatibleDC ( hDesktopDC ) <EOL> if not hCaptureDC : print ( '<STR_LIT>' ) ; sys . exit ( ) <EOL> hCaptureBitmap = gdi . CreateCompatibleBitmap ( hDesktopDC , width , height ) <EOL> if not hCaptureBitmap : print ( '<STR_LIT>' ) ; sys . exit ( ) <EOL> gdi . SelectObject ( hCaptureDC , hCaptureBitmap ) <EOL> SRCCOPY = <NUM_LIT> <EOL> gdi . BitBlt ( <EOL> hCaptureDC , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> width , height , <EOL> hDesktopDC , <EOL> left , top , <EOL> <NUM_LIT> <EOL> ) <EOL> return hCaptureBitmap <EOL> def _make_image_from_buffer ( self , hCaptureBitmap ) : <EOL> from PIL import Image <EOL> bmp_info = BITMAPINFO ( ) <EOL> bmp_header = BITMAPFILEHEADER ( ) <EOL> hdc = user32 . GetDC ( None ) <EOL> bmp_info . bmiHeader . biSize = sizeof ( BITMAPINFOHEADER ) <EOL> DIB_RGB_COLORS = <NUM_LIT:0> <EOL> gdi . GetDIBits ( hdc , <EOL> hCaptureBitmap , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> None , byref ( bmp_info ) , <EOL> DIB_RGB_COLORS <EOL> ) <EOL> bmp_info . bmiHeader . biSizeImage = int ( bmp_info . bmiHeader . biWidth * abs ( bmp_info . bmiHeader . biHeight ) * ( bmp_info . bmiHeader . biBitCount + <NUM_LIT:7> ) / <NUM_LIT:8> ) ; <EOL> size = ( bmp_info . bmiHeader . biWidth , bmp_info . bmiHeader . biHeight ) <EOL> pBuf = ( c_char * bmp_info . bmiHeader . biSizeImage ) ( ) <EOL> gdi . GetBitmapBits ( hCaptureBitmap , bmp_info . bmiHeader . biSizeImage , pBuf ) <EOL> return Image . frombuffer ( '<STR_LIT>' , size , pBuf , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> def press_and_release ( self , key ) : <EOL> '''<STR_LIT>''' <EOL> self . key_press ( key ) <EOL> self . key_release ( key ) <EOL> def key_press ( self , key ) : <EOL> '''<STR_LIT>''' <EOL> KEY_PRESS = <NUM_LIT:0> <EOL> if isinstance ( key , str ) : <EOL> vk_code = self . _vk_from_char ( key ) <EOL> else : <EOL> vk_code = key <EOL> self . _key_control ( key = vk_code , action = KEY_PRESS ) <EOL> def key_release ( self , key ) : <EOL> '''<STR_LIT>''' <EOL> KEY_RELEASE = <NUM_LIT> <EOL> if isinstance ( key , str ) : <EOL> vk_code = self . _vk_from_char ( key ) <EOL> else : <EOL> vk_code = key <EOL> self . _key_control ( key = vk_code , action = KEY_RELEASE ) <EOL> def _key_control ( self , key , action ) : <EOL> ip = INPUT ( ) <EOL> INPUT_KEYBOARD = <NUM_LIT> <EOL> ip . type = INPUT_KEYBOARD <EOL> ip . ki . wScan = <NUM_LIT:0> <EOL> ip . ki . time = <NUM_LIT:0> <EOL> a = user32 . GetMessageExtraInfo ( ) <EOL> b = cast ( a , POINTER ( c_ulong ) ) <EOL> ip . ki . wVk = key <EOL> ip . ki . dwFlags = action <EOL> user32 . SendInput ( <NUM_LIT:1> , byref ( ip ) , sizeof ( INPUT ) ) <EOL> def _vk_from_char ( self , key_char ) : <EOL> try : <EOL> return KeyConsts . key_mapping [ key_char . lower ( ) ] <EOL> except ValueError as e : <EOL> print ( e ) <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> sys . exit ( ) <EOL> def _capitalize ( self , letter ) : <EOL> self . key_press ( '<STR_LIT>' ) <EOL> self . key_press ( letter ) <EOL> self . key_release ( '<STR_LIT>' ) <EOL> self . key_release ( letter ) <EOL> def alt_press ( self , letter ) : <EOL> self . key_press ( '<STR_LIT>' ) <EOL> self . key_press ( letter ) <EOL> self . key_release ( '<STR_LIT>' ) <EOL> self . key_release ( letter ) <EOL> def ctrl_press ( self , letter ) : <EOL> self . key_press ( '<STR_LIT>' ) <EOL> self . key_press ( letter ) <EOL> self . key_release ( '<STR_LIT>' ) <EOL> self . key_release ( letter ) <EOL> def _get_unshifted_key ( self , key ) : <EOL> return KeyConsts . special_map [ key ] <EOL> def type_string ( self , input_string , delay = <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> for letter in input_string : <EOL> self . _handle_input ( letter ) <EOL> time . sleep ( delay ) <EOL> def _handle_input ( self , key ) : <EOL> if ord ( key ) in range ( <NUM_LIT> , <NUM_LIT> ) : <EOL> self . _capitalize ( key ) <EOL> elif key in KeyConsts . special_map . keys ( ) : <EOL> normalized_key = KeyConsts . special_map [ key ] <EOL> self . _capitalize ( normalized_key ) <EOL> else : <EOL> self . key_press ( key ) <EOL> self . key_release ( key ) <EOL> def type_backwards ( self , input_string , delay = <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> for letter in reversed ( input_string ) : <EOL> self . _handle_input ( letter ) <EOL> self . key_press ( '<STR_LIT>' ) <EOL> self . key_release ( '<STR_LIT>' ) <EOL> time . sleep ( delay ) <EOL> def start_program ( self , full_path ) : <EOL> '''<STR_LIT>''' <EOL> class STARTUPINFO ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , POINTER ( c_char ) ) , <EOL> ( '<STR_LIT>' , POINTER ( c_char ) ) , <EOL> ( '<STR_LIT>' , POINTER ( c_char ) ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ushort ) , <EOL> ( '<STR_LIT>' , c_ushort ) , <EOL> ( '<STR_LIT>' , POINTER ( c_ubyte ) ) , <EOL> ( '<STR_LIT>' , c_void_p ) , <EOL> ( '<STR_LIT>' , c_void_p ) , <EOL> ( '<STR_LIT>' , c_void_p ) <EOL> ] <EOL> class PROCESS_INFORMATION ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , c_void_p ) , <EOL> ( '<STR_LIT>' , c_void_p ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ] <EOL> NORMAL_PRIORITY_CLASS = <NUM_LIT> <EOL> startupinfo = STARTUPINFO ( ) <EOL> processInformation = PROCESS_INFORMATION ( ) <EOL> kernel32 . CreateProcessA ( <EOL> full_path , <EOL> None , <EOL> None , <EOL> None , <EOL> True , <EOL> <NUM_LIT:0> , <EOL> None , <EOL> None , <EOL> byref ( startupinfo ) , <EOL> byref ( processInformation ) <EOL> ) <EOL> def copy ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . key_press ( '<STR_LIT>' ) <EOL> self . key_press ( '<STR_LIT:c>' ) <EOL> self . key_release ( '<STR_LIT:c>' ) <EOL> self . key_release ( '<STR_LIT>' ) <EOL> def paste ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . key_press ( '<STR_LIT>' ) <EOL> self . key_press ( '<STR_LIT:v>' ) <EOL> self . key_release ( '<STR_LIT:v>' ) <EOL> self . key_release ( '<STR_LIT>' ) <EOL> def sleep ( self , duration ) : <EOL> '''<STR_LIT>''' <EOL> time . sleep ( duration ) <EOL> def _enumerate_windows ( self , visible = True ) : <EOL> '''<STR_LIT>''' <EOL> titles = [ ] <EOL> handlers = [ ] <EOL> def worker ( hwnd , lParam ) : <EOL> length = user32 . GetWindowTextLengthW ( hwnd ) + <NUM_LIT:1> <EOL> b = ctypes . create_unicode_buffer ( length ) <EOL> user32 . GetWindowTextW ( hwnd , b , length ) <EOL> if visible and user32 . IsWindowVisible ( hwnd ) : <EOL> title = b . value <EOL> if title : <EOL> titles . append ( title ) <EOL> handlers . append ( hwnd ) <EOL> return True <EOL> WNDENUMPROC = ctypes . WINFUNCTYPE ( BOOL , <EOL> HWND , <EOL> LPARAM ) <EOL> if not user32 . EnumWindows ( WNDENUMPROC ( worker ) , True ) : <EOL> raise ctypes . WinError ( ) <EOL> else : <EOL> return handlers , titles <EOL> def get_window_hwnd ( self , wname ) : <EOL> hwnd , win = self . _enumerate_windows ( ) <EOL> for w in win : <EOL> if wname . lower ( ) in w . lower ( ) : <EOL> return hwnd [ win . index ( w ) ] <EOL> return None <EOL> def get_window_bounds ( self ) : <EOL> rect = RECT ( ) <EOL> user32 . GetWindowRect ( self . hwnd , ctypes . byref ( rect ) ) <EOL> bbox = ( rect . left , rect . top , rect . right , rect . bottom ) <EOL> return bbox <EOL> def get_window_pos ( self ) : <EOL> x , y , right , bottom = self . get_window_bounds ( ) <EOL> return x , y <EOL> pos = property ( get_window_pos ) <EOL> def wait_for_window ( self , wname , timeout = <NUM_LIT:0> , interval = <NUM_LIT> ) : <EOL> if timeout < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> start_time = time . time ( ) <EOL> while True : <EOL> for window in self . _enumerate_windows ( ) [ <NUM_LIT:1> ] : <EOL> if wname . lower ( ) in window . lower ( ) : <EOL> return self . get_window_hwnd ( window ) <EOL> if time . time ( ) - start_time > timeout : <EOL> return False <EOL> time . sleep ( interval ) <EOL> def get_display_monitors ( self ) : <EOL> '''<STR_LIT>''' <EOL> display_coordinates = [ ] <EOL> def _monitorEnumProc ( hMonitor , hdcMonitor , lprcMonitor , dwData ) : <EOL> coordinates = ( <EOL> lprcMonitor . contents . left , <EOL> lprcMonitor . contents . top , <EOL> lprcMonitor . contents . right , <EOL> lprcMonitor . contents . bottom <EOL> ) <EOL> display_coordinates . append ( coordinates ) <EOL> return True <EOL> MonitorEnumProc = WINFUNCTYPE ( <EOL> ctypes . c_bool , <EOL> ctypes . wintypes . HMONITOR , <EOL> ctypes . wintypes . HDC , <EOL> ctypes . POINTER ( RECT ) , <EOL> ctypes . wintypes . LPARAM <EOL> ) <EOL> enum_callback = MonitorEnumProc ( _monitorEnumProc ) <EOL> user32 . EnumDisplayMonitors ( <EOL> None , <EOL> None , <EOL> enum_callback , <EOL> <NUM_LIT:0> <EOL> ) <EOL> return display_coordinates <EOL> def draw_box ( self , location , rgb_value ) : <EOL> p1_x , p1_y , p2_x , p2_y = location <EOL> width = p2_x - p1_x <EOL> height = p2_y - p1_y <EOL> for pix in range ( width ) : <EOL> self . draw_pixel ( ( p1_x + pix , p1_y ) , rgb_value ) <EOL> self . draw_pixel ( ( p1_x + pix , p2_y ) , rgb_value ) <EOL> self . draw_pixel ( ( p1_x + pix , p1_y - <NUM_LIT:1> ) , rgb_value ) <EOL> self . draw_pixel ( ( p1_x + pix , p2_y + <NUM_LIT:1> ) , rgb_value ) <EOL> for i in range ( height ) : <EOL> self . draw_pixel ( ( p1_x , p1_y + i ) , rgb_value ) <EOL> self . draw_pixel ( ( p2_x , p1_y + i ) , rgb_value ) <EOL> self . draw_pixel ( ( p1_x - <NUM_LIT:1> , p1_y + i ) , rgb_value ) <EOL> self . draw_pixel ( ( p2_x + <NUM_LIT:1> , p1_y + i ) , rgb_value ) <EOL> def draw_pixel ( self , coordinate , rgb_value ) : <EOL> '''<STR_LIT>''' <EOL> def _convert_rgb ( r , g , b ) : <EOL> r = r & <NUM_LIT> <EOL> g = g & <NUM_LIT> <EOL> b = b & <NUM_LIT> <EOL> return ( b << <NUM_LIT:16> ) | ( g << <NUM_LIT:8> ) | r <EOL> rgb = _convert_rgb ( * rgb_value ) <EOL> hdc = user32 . GetDC ( None ) <EOL> x , y = coordinate <EOL> gdi . SetPixel ( <EOL> hdc , <EOL> c_int ( x ) , <EOL> c_int ( y ) , <EOL> rgb <EOL> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> robot = Robot ( ) <EOL> robot . sleep ( <NUM_LIT:5> ) <EOL> robot . take_screenshot ( ) . save ( "<STR_LIT>" , "<STR_LIT>" ) </s>
