Esempio n. 1
0
def _getMultipleWindowValues(hwnd, getCountMessage, getValueMessage):
    '''A common pattern in the Win32 API is that in order to retrieve a
    series of values, you use one message to get a count of available
    items, and another to retrieve them. This internal utility function
    performs the common processing for this pattern.

    Arguments:
    hwnd                Window handle for the window for which items should be
                        retrieved.
    getCountMessage     Item count message.
    getValueMessage     Value retrieval message.

    Returns:            Retrieved items.'''
    result = []

    VALUE_LENGTH = 256
    bufferlength_int = struct.pack('i', VALUE_LENGTH)  # This is a C style int.

    valuecount = win32gui.SendMessage(hwnd, getCountMessage, 0, 0)
    for itemIndex in range(valuecount):
        valuebuffer = array.array(
            'c',
            bufferlength_int + " " * (VALUE_LENGTH - len(bufferlength_int)))
        valueLength = win32gui.SendMessage(hwnd, getValueMessage, itemIndex,
                                           valuebuffer)
        result.append(valuebuffer.tostring()[:valueLength])
    return result
Esempio n. 2
0
def click_it(pos):  #第三种
    handle = win32gui.WindowFromPoint(pos)
    client_pos = win32gui.ScreenToClient(handle, pos)
    tmp = win32api.MAKELONG(client_pos[0], client_pos[1])
    win32gui.SendMessage(handle, win32con.WM_ACTIVATE, win32con.WA_ACTIVE, 0)
    win32gui.SendMessage(handle, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON,
                         tmp)
    win32gui.SendMessage(handle, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON,
                         tmp)
def abre_arquivo(dir):
    # Loop até que a caixa de diálogo Open seja exibida
    hdlg = 0
    while hdlg == 0:
        hdlg = win32gui.FindWindow(None, "Abrir")

    # Define o nome do arquivo e pressione a tecla Enter
    hwnd = win32gui.FindWindowEx(hdlg, 0, "ComboBoxEx32", None)
    hwnd = win32gui.FindWindowEx(hwnd, 0, "ComboBox", None)
    hwnd = win32gui.FindWindowEx(hwnd, 0, "Edit", None)
    win32gui.SendMessage(hwnd, win32con.WM_SETTEXT, None, dir)
    # Pressiona o botão Salvar
    hwnd = win32gui.FindWindowEx(hdlg, 0, "Button", "&Abrir")
    win32gui.SendMessage(hwnd, win32con.BM_CLICK, None, None)
def send_qq(to_who, msg):
    """发送qq消息
    to_who:qq消息接收人
    msg:需要发送的消息
    """
    # 将消息写到剪贴板
    setText(msg)
    # 获取qq窗口句柄
    qq = win32gui.FindWindow(None, to_who)
    # 投递剪贴板消息到QQ窗体
    win32gui.SendMessage(qq, 258, 22, 2080193)
    win32gui.SendMessage(qq, 770, 0, 0)
    # 模拟按下回车键
    win32gui.SendMessage(qq, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
    win32gui.SendMessage(qq, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
Esempio n. 5
0
def setEditText(hwnd, text, append=False):
    '''Set an edit control's text.
    
    Arguments:
    hwnd            The edit control's hwnd.
    text            The text to send to the control. This can be a single
                    string, or a sequence of strings. If the latter, each will
                    be become a a seperate line in the control.
    append          Should the new text be appended to the existing text?
                    Defaults to False, meaning that any existing text will be
                    replaced. If True, the new text will be appended to the end
                    of the existing text.
                    Note that the first line of the new text will be directly
                    appended to the end of the last line of the existing text.
                    If appending lines of text, you may wish to pass in an
                    empty string as the 1st element of the 'text' argument.

    Usage example:  print "Enter various bits of text."
                    setEditText(editArea, "Hello, again!")
                    time.sleep(.5)
                    setEditText(editArea, "You still there?")
                    time.sleep(.5)
                    setEditText(editArea, ["Here come", "two lines!"])
                    time.sleep(.5)
                    
                    print "Add some..."
                    setEditText(editArea, ["", "And a 3rd one!"], append=True)
                    time.sleep(.5)'''

    # Ensure that text is a list
    try:
        text + ''
        text = [text]
    except TypeError:
        pass

    # Set the current selection range, depending on append flag
    if append:
        win32gui.SendMessage(hwnd, win32con.EM_SETSEL, -1, 0)
    else:
        win32gui.SendMessage(hwnd, win32con.EM_SETSEL, 0, -1)

    # Send the text
    win32gui.SendMessage(hwnd, win32con.EM_REPLACESEL, True,
                         os.linesep.join(text))
Esempio n. 6
0
def selectListboxItem(hwnd, item):
    '''Selects a specified item in a list box control.

    Arguments:
    hwnd            Window handle of the required list box.
    item            The reqired item. Either an index, of the text of the
                    required item.

    Usage example:  TODO
    '''
    try:  # item is an index Use this to select
        0 + item
        win32gui.SendMessage(hwnd, win32con.LB_SETCURSEL, item, 0)
        _sendNotifyMessage(hwnd, win32con.LBN_SELCHANGE)
    except TypeError:  # Item is a string - find the index, and use that
        items = getListboxItems(hwnd)
        itemIndex = items.index(item)
        selectListboxItem(hwnd, itemIndex)
Esempio n. 7
0
def _sendNotifyMessage(hwnd, nofifyMessage):
    '''Send a notify message to a control.'''
    win32gui.SendMessage(
        win32gui.GetParent(hwnd), win32con.WM_COMMAND,
        _buildWinLong(nofifyMessage,
                      win32api.GetWindowLong(hwnd, win32con.GWL_ID)), hwnd)
Esempio n. 8
0
inp_xpath = "//*[@id='main']/footer/div/div/div[2]/div/span/div/div/ul/li[3]/button/span"
button = web_driver.find_elements_by_xpath(inp_xpath)
button[0].click()
time.sleep(10)  # segundo. Esta pausa é necessária

hdlg = 0
while hdlg == 0:
    hdlg = win32gui.FindWindow(None, "Abrir")

time.sleep(1)  # second. This pause is needed

# Set filename and press Enter key
hwnd = win32gui.FindWindowEx(hdlg, 0, "ComboBoxEx32", None)
hwnd = win32gui.FindWindowEx(hwnd, 0, "ComboBox", None)
hwnd = win32gui.FindWindowEx(hwnd, 0, "Edit", None)

filename = 'boleto.txt'
win32gui.SendMessage(hwnd, win32con.WM_SETTEXT, None, filename)

# Press Save button
hwnd = win32gui.FindWindowEx(hdlg, 0, "Button", "&Abrir")

win32gui.SendMessage(hwnd, win32con.BM_CLICK, None, None)

element = web_driver.find_element_by_xpath(
    '//*[@id="app"]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span/div/div'
)
web_driver.execute_script("arguments[0].click();", element)

web_driver.implicitly_wait(100)
Esempio n. 9
0
win32api.SendMessage(handle, win32con.WM_SETTEXT, 0,
                     os.path.abspath(fgFilePath).encode('gbk'))

# 控件点击确定,处理消息后返回0
# 参数:窗口句柄; 消息类型; 参数WParam HIWORD为0(未使用),LOWORD为控件的ID; 参数IParam  0(未使用),确定控件的句柄
win32api.SendMessage(Mhandle, win32con.WM_COMMAND, 1, confirmBTN_handle)

# 获取窗口文本不含截尾空字符的长度
# 参数:窗口句柄; 消息类型; 参数WParam; 参数IParam
bufSize = win32api.SendMessage(subHandle, win32con.WM_GETTEXTLENGTH, 0, 0) + 1
# 利用api生成Buffer
strBuf = win32gui.PyMakeBuffer(bufSize)
print(strBuf)
# 发送消息获取文本内容
# 参数:窗口句柄; 消息类型;文本大小; 存储位置
length = win32gui.SendMessage(subHandle, win32con.WM_GETTEXT, bufSize, strBuf)
# 反向内容,转为字符串
# text = str(strBuf[:-1])

address, length = win32gui.PyGetBufferAddressAndLen(strBuf)
text = win32gui.PyGetString(address, length)
# print('text: ', text)

# 鼠标单击事件
#鼠标定位到(30,50)
win32api.SetCursorPos([30, 150])
#执行左单键击,若需要双击则延时几毫秒再点击一次即可
win32api.mouse_event(
    win32con.MOUSEEVENTF_LEFTUP | win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
#右键单击
win32api.mouse_event(