How to send Ctrl-L keyboard event to dialog without human intervention?

This is simultaneous post with stackoverflow.

I tried to control an Chrome extension without human intervention.
In the extension, user have to select a directory with file chooser dialog of Chromium browser.
Now I attempted to input directory path as a string so I would like to send Ctrl-L keyboard event to dialog with at-spi2
But I can not do it…

Probably it can achieve with Atspi.generate_keyboard_event but I have no idea how to do it actually…

My environment is ArchLinux, GNOME 45.4, Wayland

def search_chrome_filechooser():
    if not Atspi.is_initialized():
        err = Atspi.init()
        if err != 0:
            print("Something Error:", err)
            return

    root = Atspi.get_desktop(0)
    app = search_widget(root, "xdg-desktop-portal-gnome", "application")
    if app == None:
        print("app not found")
        return
    dialog = search_widget(app, role_name="dialog")
    if dialog is None:
        print("file chooser dialog not found")
        if Atspi.is_initialized():
            Atspi.exit()
        return


    Atspi.generate_keyboard_event(29, None, Atspi.KeySynthType.PRESS)
    Atspi.generate_keyboard_event(38, None, Atspi.KeySynthType.PRESSRELEASE)
    if Atspi.is_initialized():
        Atspi.exit()


def search_widget(root, name: str|None=None, role_name:str|None=None):
    widget = root
    if widget == None:
        return None
    if name == None and role_name == None:
        return
    widget_name = widget.get_name()
    widget_role_name = widget.get_role_name()
    if name == widget_name and role_name == None:
        return widget
    elif name == None and role_name == widget_role_name:
        return widget
    elif name == widget_name and role_name == widget_role_name:
        return widget
    num = widget.get_child_count()
    for v in range(num):
        child = widget.get_child_at_index(v)
        if (result := search_widget(child, name, role_name)) != None:
            return result

search_chrome_filechooser()

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.