Skip to content

[Bug]: keyboard.type_text("a") does not send correct KeyDown/KeyUp events #367

@pjsg

Description

@pjsg

Checklist before reporting

  • I have searched for similar issues and didn't find a duplicate.
  • I have updated to the latest version of pydoll to verify the issue still exists.

pydoll Version

2.20.2

Python Version

3.12.6

Operating System

macOS

Bug Description

I want to send a lower-case A as keyboard input. You can't do this with keyboard.press as that takes a member of the Key enumeration, and that only has uppercase letters. However, I had hoped that type_text would be able to do it. However, according to https://keycode.info/ the keydown event that gets sent is actually for a keycode of 0.

Steps to Reproduce

Run the test program below and observe that it display the wrong keycode in the browser (using the type_text interface). Then it proceeds after wait and displays the keycode for an uppercase A by using the press interface

Code Example

from pydoll.browser import Chrome
import asyncio

from pydoll.constants import Key

async def test():
    browser = Chrome()
    try:
        tab = await browser.start()
        await tab.go_to("https://keycode.info")
        await asyncio.sleep(5)

        print("About to type 'a'")
        await tab.keyboard.type_text("a", humanize=False)
        print("Typed 'a'")
        await asyncio.sleep(10)
        print("About to press 'A'")
        await tab.keyboard.press(Key.A)
        print("Pressed 'A'")
        await asyncio.sleep(10)
    finally:
        await browser.stop()


if __name__ == "__main__":
    asyncio.run(test())

Expected Behavior

It should show that the person typed a lowercase 'a'. You can see this by typing a lowercase 'a' into https://keycode.info

Actual Behavior

It displayed the wrong keycode.

Relevant Log Output

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions