botasaurus icon indicating copy to clipboard operation
botasaurus copied to clipboard

No way of doing keypresses

Open Goolyio opened this issue 5 months ago • 3 comments

There currently is no way if doing key presses, for example I want to use tab to move between inputs for more realistic behaviour and input focussing

Goolyio avatar Jul 11 '25 15:07 Goolyio

Bump

doshibadev avatar Jul 28 '25 01:07 doshibadev

@Goolyio In the meantime i found that you can use pyautogui to press the necessary key

doshibadev avatar Jul 28 '25 08:07 doshibadev

@doshibadev I managed to do it using custom CDP commands

from botasaurus_driver import cdp

def press_enter(driver: Driver):
    driver.run_cdp_command(cdp.input_.dispatch_key_event(
        type_="rawKeyDown",
        native_virtual_key_code=13,
        windows_virtual_key_code=13,
        unmodified_text="\r",
        text="\r"
    ))

    driver.run_cdp_command(cdp.input_.dispatch_key_event(
        type_="char",
        native_virtual_key_code=13,
        windows_virtual_key_code=13,
        unmodified_text="\r",
        text="\r"
    ))
    
    driver.run_cdp_command(cdp.input_.dispatch_key_event(
        type_="keyUp",
        native_virtual_key_code=13,
        windows_virtual_key_code=13,
        unmodified_text="\r",
        text="\r"
    ))

Goolyio avatar Jul 28 '25 09:07 Goolyio