使用Python显示IE的菜单栏项

2024-05-31 23:50:01 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python中,是否可以列出internetexplorerversion8的文件菜单(如图所示)的所有项目?在

以下是我想列出的:

enter image description here


Tags: 文件项目菜单internetexplorerversion8
1条回答
网友
1楼 · 发布于 2024-05-31 23:50:01

你只需要知道目标窗口的标题。然后,您可以模拟鼠标单击或使用Alt/菜单+F快捷方式打开菜单。在

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from ctypes import windll

def main():
    find_window = windll.user32.FindWindowW
    send_message = windll.user32.SendMessageW

    window_name = u""
    window_handle = find_window(0, window_name)

    if window_handle > 0:
        show_menu(handle)
    else:
        print("Window handle not found")


if __name__ == "__main__":
    main()

如果需要第一个解决方案(单击鼠标),则添加:

^{pr2}$

否则(按键),使用:

VK_MENU = 0x12
VK_F = 0x46

def show_menu(handle):
    for key in (VK_MENU, VK_F):
        send_message(window_handle, WM_KEYDOWN, key, 0)
        send_message(window_handle, WM_KEYUP, key, 0)

希望这有帮助。在

相关问题 更多 >