Ejemplo n.º 1
0
def CreateComboBox(parent, pos, size, style = wc.CBS_DROPDOWNLIST):
    parent_hwnd = parent.GetSafeHwnd()
    hwnd = gui.CreateWindow("COMBOBOX", "Blarg",
        wc.WS_CHILD | wc.CBS_DROPDOWNLIST,
        pos[0], pos[1], size[0], size[1],
        parent_hwnd, 0, 0, None)
    return ui.CreateWindowFromHandle(hwnd)
Ejemplo n.º 2
0
    def __init__(self, dlg, id):
        self._parent = dlg
        hwnd = Sdk.GetDlgItem(dlg.GetSafeHwnd(), id)
        window.Wnd.__init__(self, win32ui.CreateWindowFromHandle(hwnd))

        self._enabled = 0
        if not self._enabled:
            self.EnableWindow(0)

        self.SetTicFreq(5)
        self.SetLineSize(5)
        self.SetPageSize(20)
        self.SetRange(0, 100)

        self._keyTimes = [0.0, 1.0]
        self._copyKeyTime = None
        self._copyIndex = None

        self._markerColor = 0, 0, 0
        self._selectedMarkerColor = 255, 0, 0
        self._copingMarkerColor = 255, 150, 150

        dlg.HookMessage(self.OnHScroll, win32con.WM_HSCROLL)

        self._selected = -1
        self._dragging = None

        self._listener = None

        # preview support
        self.fiber = None
        self.previewdur = 5.0
Ejemplo n.º 3
0
    def __init__(self, name, keys_vector):

        # search for window handle by title
        matches = []

        def callback(hndl, extra):
            s = win32gui.GetWindowText(hndl)
            if s.startswith(name):
                matches.append((hndl, s))

        win32gui.EnumWindows(callback, None)

        if len(matches) > 1:
            raise GameControlException("More than one matching hndl found")

        if len(matches) == 0:
            raise GameControlException("No window found matching title %s" %
                                       (name))

        (ihndl, self.window_name), = matches

        self.pycwnd = win32ui.CreateWindowFromHandle(ihndl)

        self.keys_vector = keys_vector
        self.keys_state = [None for _ in keys_vector]
Ejemplo n.º 4
0
 def __init__(self,parent,rc):
     vv=vview.CreateVViewer()
     vv.CreateWindow(parent.GetSafeHwnd())
     wnd=win32ui.CreateWindowFromHandle(vv.GetSafeHwnd())
     window.Wnd.__init__(self,wnd)
     wnd.SetWindowPos(0, rc, win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER)
     self._vvctrl=vv
Ejemplo n.º 5
0
def axw__init__(self,
                parent,
                ID=-1,
                pos=wx.DefaultPosition,
                size=wx.DefaultSize,
                style=0):

    # init base classes
    pywin.mfc.activex.Control.__init__(self)
    wx.Window.__init__(self, parent, -1, pos, size,
                       style | wx.NO_FULL_REPAINT_ON_RESIZE)
    self.this.own(
        False
    )  # this should be set in wx.Window.__init__ when it calls _setOORInfo, but...

    win32ui.EnableControlContainer()
    self._eventObj = self._eventObj  # move from class to instance

    # create a pythonwin wrapper around this wxWindow
    handle = self.GetHandle()
    self._wnd = win32ui.CreateWindowFromHandle(handle)

    # create the control
    sz = self.GetSize()
    self.CreateControl(self._name, WS_TABSTOP | WS_VISIBLE,
                       (0, 0, sz.width, sz.height), self._wnd, ID)

    # init the ax events part of the object
    self._eventBase.__init__(self, self._dispobj_)

    # hook some wx events
    self.Bind(wx.EVT_SIZE, self.axw_OnSize)
Ejemplo n.º 6
0
 def __init__(self, parent, pos, size, style=wc.CBS_DROPDOWNLIST):
     parent_hwnd = parent.GetSafeHwnd()
     self.hwnd = gui.CreateWindow("COMBOBOX", "Blarg",
                                  wc.WS_CHILD | wc.CBS_DROPDOWNLIST, pos[0],
                                  pos[1], size[0], size[1], parent_hwnd, 0,
                                  0, None)
     self.pycwnd = ui.CreateWindowFromHandle(self.hwnd)
     print "ComboBox: pycwnd =", self.pycwnd  ###
Ejemplo n.º 7
0
 def attach_to_parent(self):
     ListBox.attach_to_parent(self)
     wnd = win32ui.CreateWindowFromHandle(self._hwnd)
     wnd.SubclassDlgItem(self._id, self._parent)
     wnd.HookMessage(self.onLButtonDown, win32con.WM_LBUTTONDOWN)
     wnd.HookMessage(self.onLButtonUp, win32con.WM_LBUTTONUP)
     wnd.HookMessage(self.onMouseMove, win32con.WM_MOUSEMOVE)
     self._mfcwnd = wnd
Ejemplo n.º 8
0
    def __init__(self):
        self.nome_do_processo = None
        self.pegar_nome()

        self.hwnd = win32gui.FindWindow(None, self.nome_do_processo)
        win = win32ui.CreateWindowFromHandle(self.hwnd)

        # dicionario teclado
        self.dicionario_teclado = {'tab': 0x09, 'f1': 0x70, '0': 0x30, '1': 0x31, '2': 0x32, '3': 0x33,
                                  '4': 0x34, '5': 0x35, '6': 0x36, '7': 0x37, '8': 0x38, '9': 0x39}
Ejemplo n.º 9
0
	def typer(self,stringIn=None):
		PyCWnd = win32ui.CreateWindowFromHandle(self.hwnd)
		for s in stringIn :
			if s == "\n":
				self.hwnd.SendMessage(win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
				self.hwnd.SendMessage(win32con.WM_KEYUP, win32con.VK_RETURN, 0)
			else:
				print ('Ord %s' % ord(s))
				PyCWnd.SendMessage(win32con.WM_CHAR, ord(s), 0)
		PyCWnd.UpdateWindow()
Ejemplo n.º 10
0
 def OnKillFocus(self, msg):
     # If we are losing focus to another in this app, reset the main frame's active view.
     hwnd = wparam = msg[2]
     try:
         wnd = win32ui.CreateWindowFromHandle(hwnd)
         reset = wnd.GetTopLevelFrame() == self.GetTopLevelFrame()
     except win32ui.error:
         reset = 0  # Not my window
     if reset: self.GetParentFrame().SetActiveView(None)
     return 1
Ejemplo n.º 11
0
    def _win_create_tabctrl(self):
        _win = gui.CreateWindow(cc.WC_TABCONTROL,
                                '',
                                wc.WS_CHILD | wc.WS_CLIPSIBLINGS | wc.WS_VISIBLE,
                                0, 0, 1, 1,
                                win_none.GetSafeHwnd(),
                                0, 0, None)
        _pywin = ui.CreateWindowFromHandle(_win)

        _pywin.HookMessage(self._win_wm_notify, wc.WM_NOTIFY)

        return _pywin
def main():
    window_name = "Untitled - Notepad"
    hwnd = win32gui.FindWindow(None, window_name)
    hwnd = get_inner_windows(hwnd)['Edit']
    win = win32ui.CreateWindowFromHandle(hwnd)

    #win.SendMessage(win32con.WM_CHAR, ord('A'), 0)
    #win.SendMessage(win32con.WM_CHAR, ord('B'), 0)
    #win.SendMessage(win32con.WM_KEYDOWN, 0x1E, 0)
    #sleep(0.5)
    #win.SendMessage(win32con.WM_KEYUP, 0x1E, 0)
    win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, 0x41, 0)
    sleep(0.5)
    win32api.SendMessage(hwnd, win32con.WM_KEYUP, 0x41, 0)
Ejemplo n.º 13
0
    def SetSite(self, unknown):
        if unknown:
            # retrieve the parent window interface for this site
            olewindow = unknown.QueryInterface(pythoncom.IID_IOleWindow)
            # ask the window for its handle
            hwndparent = olewindow.GetWindow()

            # first get a command target
            cmdtarget = unknown.QueryInterface(axcontrol.IID_IOleCommandTarget)
            # then travel over to a service provider
            serviceprovider = cmdtarget.QueryInterface(
                pythoncom.IID_IServiceProvider)
            # finally ask for the internet explorer application, returned as a
            # dispatch object
            self.webbrowser = win32com.client.Dispatch(
                serviceprovider.QueryService(
                    '{0002DF05-0000-0000-C000-000000000046}',
                    pythoncom.IID_IDispatch))

            # now create and set up the toolbar
            self.toolbar = IEToolbarCtrl(hwndparent)

            buttons = [
                ('Visit PyWin32 Homepage', self.on_first_button),
                ('Another Button', self.on_second_button),
                ('Yet Another Button', self.on_third_button),
            ]

            self._command_map = {}
            # wrap our parent window so we can hook message handlers
            window = win32ui.CreateWindowFromHandle(hwndparent)

            # add the buttons
            for i in range(len(buttons)):
                button = TBBUTTON()
                name, func = buttons[i]
                id = 0x4444 + i
                button.iBitmap = -2
                button.idCommand = id
                button.fsState = commctrl.TBSTATE_ENABLED
                button.fsStyle = commctrl.TBSTYLE_BUTTON
                button.iString = name
                self._command_map[0x4444 + i] = func
                self.toolbar.AddButtons(button)
                window.HookMessage(
                    self.toolbar_command_handler,
                    win32con.WM_COMMAND)
        else:
            # lose all references
            self.webbrowser = None
Ejemplo n.º 14
0
 def grab_pixel(self, x, y):
     """ x,y -> (r,g,b) """
     win = win32ui.CreateWindowFromHandle(self.hwnd)
     dc = win.GetWindowDC()
     px = hex(dc.GetPixel(x, y))
 
     # @TODO: just do the math :)
     # note that the values are "backwards" from rgb
     if len(px) < 4: px += ("0" * (8-len(px)))
     b = int(px[2:4], 16)
     g = int(px[4:6], 16)
     r = int(px[6:8], 16)
     
     return tuple([r, g, b])
Ejemplo n.º 15
0
 def on_key(self, e):
     self.parse(e)
     if self.is_key_down and self.is_autorepeat:
         return True
     # save current foreground window
     if self.is_digit() and self.is_key_down and self.is_alt_shift_down():
         hwnd = user32.GetForegroundWindow()
         wnd = win32ui.CreateWindowFromHandle(hwnd)
         self.saved_wnds[self.ch] = wnd
         print '*' * 70
         for index, wnd in self.saved_wnds.items():
             print '{:2} {}'.format(index, wnd.GetWindowText())
         print '*' * 70
     # restore to previous foreground window
     elif self.is_digit() and self.is_key_down and self.is_ctrl_alt_down():
         index = self.ch
         if self.valid_window(index):
             keys_to_eat = [
                 self.key_id, win32con.VK_LMENU, win32con.VK_LCONTROL
             ]
             keys_stats = [
                 win32api.GetAsyncKeyState(key) & 0x8000
                 for key in keys_to_eat
             ]
             for key in keys_to_eat:
                 simulate.up(key)
             if not self.bring_window_to_foreground(index):
                 print 'alt-tab activate'
                 simulate.down(win32con.VK_LMENU)
                 simulate.tap(win32con.VK_TAB)
                 simulate.down(win32con.VK_LSHIFT)
                 simulate.tap(win32con.VK_TAB)
                 simulate.up(win32con.VK_LSHIFT)
                 simulate.up(win32con.VK_LMENU)
             for key, stat in reversed(zip(keys_to_eat, keys_stats)):
                 if stat:
                     simulate.down(key)
     return True
Ejemplo n.º 16
0
    def make_pyc_wnd(self, hwnd=None):
        """
        Creates a python window object from the hwnd handle found earlier

        Args:
            hwnd (int): The title of the window we are looking for
                if hwnd is not supplied, it will use the one found in an earlier
                call to get_hwnd_by_title

        Returns:
            pycwnd: a handle to the window we are looking for

        """
        logging.debug("Make pyc hwnd with handle 0x%x" % hwnd)
        if hwnd is None:
            logging.debug("Hwnd not supplied, using {} instead".format(
                self.hwnd))
            hwnd = self.hwnd

        if hwnd == 0:
            raise ValueError('Hwnd is not a valid handle or window not found')

        self.pycwnd = win32ui.CreateWindowFromHandle(hwnd)
        return self.pycwnd
Ejemplo n.º 17
0
import time
import win32api
import win32gui
import win32ui
from ctypes import windll
import win32con
from PIL import ImageGrab
from pytesseract import *

import aircv
import os
import random

hWin = win32gui.FindWindow(None, '雷电模拟器')
ch = win32gui.FindWindowEx(hWin, 0, None, 'TheRender')
b = win32ui.CreateWindowFromHandle(ch)
x = 0
y = 38
rect = win32gui.GetWindowRect(hWin)
w = rect[2] - rect[0] - 38
h = rect[3] - rect[1] - 38
hwndDC = win32gui.GetWindowDC(hWin)  # 根据窗口句柄获取窗口的设备上下文DC(Divice Context)
mfcDC = win32ui.CreateDCFromHandle(hwndDC)  # 根据窗口的DC获取mfcDC
saveDC = mfcDC.CreateCompatibleDC()  # mfcDC创建可兼容的DC
saveBitMap = win32ui.CreateBitmap()  # 创建bigmap准备保存图片

saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)  # 为bitmap开辟空间

state_map = [
    ['battle_complete', 'touch.png'],
    ['get_new_pm', 'state_newpm.png'],
Ejemplo n.º 18
0
    bmpinfo = saveBitMap.GetInfo()
    bmpstr = saveBitMap.GetBitmapBits(True)

    im = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']),
                          bmpstr, 'raw', 'BGRX', 0, 1)

    win32gui.DeleteObject(saveBitMap.GetHandle())
    saveDC.DeleteDC()
    mfcDC.DeleteDC()
    win32gui.ReleaseDC(handle, hwndDC)

    return im


py_hwnd = win32ui.CreateWindowFromHandle(hwnd)

py_hwnd.SendMessage(win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON,
                    (510 << 16) | 100)
py_hwnd.SendMessage(win32con.WM_LBUTTONUP, win32con.MK_LBUTTON,
                    (510 << 16) | 100)

exit()

while 1:
    sleep(1)
    py_hwnd.SendMessage(win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON,
                        (510 << 16) | 100)
    py_hwnd.SendMessage(win32con.WM_LBUTTONUP, win32con.MK_LBUTTON,
                        (510 << 16) | 100)
    py_hwnd.PostMessage(win32con.WM_KEYDOWN, win32con.VK_ESCAPE, 0)
Ejemplo n.º 19
0
 def _forward_reflected_message(self, lParam, method_name, *args):
     wnd = ui.CreateWindowFromHandle(lParam)
     meth = getattr(wnd, method_name, None)
     if meth:
         meth(*args)
def restore_console_focus():
    """Restore the focus to the IPython console."""
    h = win32console.GetConsoleWindow()
    console_window = win32ui.CreateWindowFromHandle(h)
    console_window.SetForegroundWindow()
Ejemplo n.º 21
0
def create_window(handle):
    PyCwnd = win32ui.CreateWindowFromHandle(handle)
    return PyCwnd
Ejemplo n.º 22
0
 def create_wnd_from_handle(self):
     window.Wnd.__init__(self, win32ui.CreateWindowFromHandle(self._hwnd))
Ejemplo n.º 23
0
import win32gui, win32ui, time

# w = win32ui.GetMainFrame()
dw = win32gui.GetDesktopWindow()
w = win32ui.CreateWindowFromHandle(dw)
t1 = time.time()
count = 0
while count < 1000:
    dc = w.GetWindowDC()
    dc.GetPixel(60, 20)
    dc.DeleteDC()
    count += 1
t2 = time.time()
tf = t2 - t1
it_per_sec = int(count / tf)
print(str(it_per_sec) + " iterations per second")
Ejemplo n.º 24
0
def make_pycwnd(hwnd):
    logging.info("[ENTER] make_pycwnd")
    PyCWnd = win32ui.CreateWindowFromHandle(hwnd)
    return PyCWnd
Ejemplo n.º 25
0
 def make_pycwnd(self, hwnd):
   PyCWnd = win32ui.CreateWindowFromHandle(hwnd)
   return PyCWnd
Ejemplo n.º 26
0
 def hookmessage(self, cb, msgid):
     if not self._hwnd: raise error, 'os control has not been created'
     wnd = window.Wnd(win32ui.CreateWindowFromHandle(self._hwnd))
     wnd.HookMessage(cb, msgid)