
    &th2                         d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ erddlmZ  G d	 d
e          Z G d de          Z G d de          ZdS )zKeyboard and Mouse module.    N)AnyDictTYPE_CHECKING)
CDPSession)PyppeteerError)keyDefinitions)
merge_dict)Setc            	           e Zd ZdZdeddfdZddedededdfd	Z	dede
fd
ZdedefdZdeddfdZdeddfdZddedededdfdZddedededdfdZdS )Keyboarda  Keyboard class provides as api for managing a virtual keyboard.

    The high level api is :meth:`type`, which takes raw characters and
    generate proper keydown, keypress/input, and keyup events on your page.

    For finer control, you can use :meth:`down`, :meth:`up`, and
    :meth:`sendCharacter` to manually fire events as if they were generated
    from a real keyboard.

    An example of holding down ``Shift`` in order to select and delete some
    text:

    .. code::

        await page.keyboard.type('Hello, World!')
        await page.keyboard.press('ArrowLeft')

        await page.keyboard.down('Shift')
        for i in ' World':
            await page.keyboard.press('ArrowLeft')
        await page.keyboard.up('Shift')

        await page.keyboard.press('Backspace')
        # Result text will end up saying 'Hello!'.

    An example of pressing ``A``:

    .. code::

        await page.keyboard.down('Shift')
        await page.keyboard.press('KeyA')
        await page.keyboard.up('Shift')
    clientreturnNc                 H    || _         d| _        t                      | _        d S )Nr   )_client
_modifiersset_pressedKeys)selfr   s     c/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/pyppeteer/input.py__init__zKeyboard.__init__5   s"    &)ee    keyoptionskwargsc                   K   t          ||          }|                     |          }|d         | j        v }| j                            |d                    | xj        |                     |d                   z  c_        |                    d          }||d         }| j                            d|rdnd| j        |d         |d         |d         ||||d	         |d	         d
k    d
           d{V  dS )ai  Dispatch a ``keydown`` event with ``key``.

        If ``key`` is a single character and no modifier keys besides ``Shift``
        are being held down, and a ``keypress``/``input`` event will also
        generated. The ``text`` option can be specified to force an ``input``
        event to be generated.

        If ``key`` is a modifier key, like ``Shift``, ``Meta``, or ``Alt``,
        subsequent key presses will be sent with that modifier active. To
        release the modifier key, use :meth:`up` method.

        :arg str key: Name of key to press, such as ``ArrowLeft``.
        :arg dict options: Option can have ``text`` field, and if this option
            specified, generate an input event with this text.

        .. note::
            Modifier keys DO influence :meth:`down`. Holding down ``shift``
            will type the text in upper case.
        coder   textNInput.dispatchKeyEventkeyDown
rawKeyDownkeyCodelocation   )
type	modifierswindowsVirtualKeyCoder   r   r   unmodifiedText
autoRepeatr"   isKeypad)	r	   _keyDescriptionForStringr   addr   _modifierBitgetr   send)r   r   r   r   descriptionr(   r   s          r   downzKeyboard.down:   s1     * Wf--33C88 (D,==
k&12224,,[-?@@@{{6""<v&Dl 8!%7II<%0%;'u%"$#J/#J/14;
 ;
   	 	 	 	 	 	 	 	 	r   c                 F    |dk    rdS |dk    rdS |dk    rdS |dk    rdS d	S )
NAlt   Control   Meta   Shift   r    )r   r   s     r   r,   zKeyboard._modifierBitg   sA    %<<1)1&==1'>>1qr   	keyStringc                 B   | j         dz  }dddddd}t          j        |          }|st          d|           d|v r|d         |d<   |r |                    d          r|d         |d<   d|v r|d         |d<   |r |                    d	          r|d	         |d<   d
|v r|d
         |d
<   d|v r|d         |d<   t	          |d                   dk    r|d         |d<   d|v r|d         |d<   |r |                    d          r|d         |d<   | j         dz  rd|d<   |S )Nr9    r   )r   r!   r   r   r"   zUnknown key: r   shiftKeyr!   shiftKeyCoder   r"   r3   r   	shiftTexti)r   r   r-   r   len)r   r;   shiftr/   
definitions        r   r*   z!Keyboard._keyDescriptionForStringr   s   !#
 
 *-i88
 	> !<!<!<===J!+E!2K 	8Z^^J// 	8!+J!7K
""%/	%:K	" 	@Z^^N33 	@%/%?K	"Z",V"4K##&0&<K
#{5!""a''"-e"4KZ",V"4K 	:Z^^K00 	:",["9K?R 	%"$Kr   c           
      p  K   |                      |          }| xj        |                     |d                    z  c_        |d         | j        v r | j                            |d                    | j                            dd| j        |d         |d         |d         |d         d           d{V  dS )	zyDispatch a ``keyup`` event of the ``key``.

        :arg str key: Name of key to release, such as ``ArrowLeft``.
        r   r   r   keyUpr!   r"   )r$   r%   r   r&   r   r"   N)r*   r   r,   r   remover   r.   )r   r   r/   s      r   upzKeyboard.up   s      
 33C88D--k%.@AAAAv$"333$$[%8999l 8u%%0%;'#J/;
 ;
   	 	 	 	 	 	 	 	 	r   charc                 P   K   | j                             dd|i           d{V  dS )aB  Send character into the page.

        This method dispatches a ``keypress`` and ``input`` event. This does
        not send a ``keydown`` or ``keyup`` event.

        .. note::
            Modifier keys DO NOT effect :meth:`sendCharacter`. Holding down
            ``shift`` will not type the text in upper case.
        zInput.insertTextr   N)r   r.   )r   rH   s     r   sendCharacterzKeyboard.sendCharacter   s=       l 2VTNCCCCCCCCCCCr   r   c                 $  K   t          ||          }|                    dd          }|D ]d}|t          v r|                     |d|i           d{V  n|                     |           d{V  |rt          j        |dz             d{V  edS )a  Type characters into a focused element.

        This method sends ``keydown``, ``keypress``/``input``, and ``keyup``
        event for each character in the ``text``.

        To press a special key, like ``Control`` or ``ArrowDown``, use
        :meth:`press` method.

        :arg str text: Text to type into a focused element.
        :arg dict options: Options can have ``delay`` (int|float) field, which
          specifies time to wait between key presses in milliseconds. Defaults
          to 0.

        .. note::
            Modifier keys DO NOT effect :meth:`type`. Holding down ``shift``
            will not type the text in upper case.
        delayr   N  )r	   r-   r   pressrJ   asynciosleep)r   r   r   r   rL   rH   s         r   r$   zKeyboard.type   s      & Wf--GQ'' 	2 	2D~%%jj'78888888888((......... 2mEDL111111111	2 	2r   c                    K   t          ||          }|                     ||           d{V  d|v r#t          j        |d         dz             d{V  |                     |           d{V  dS )a  Press ``key``.

        If ``key`` is a single character and no modifier keys besides
        ``Shift`` are being held down, a ``keypress``/``input`` event will also
        generated. The ``text`` option can be specified to force an input event
        to be generated.

        :arg str key: Name of key to press, such as ``ArrowLeft``.

        This method accepts the following options:

        * ``text`` (str): If specified, generates an input event with this
          text.
        * ``delay`` (int|float): Time to wait between ``keydown`` and
          ``keyup``. Defaults to 0.

        .. note::
            Modifier keys DO effect :meth:`press`. Holding down ``Shift`` will
            type the text in upper case.
        NrL   rM   )r	   r0   rO   rP   rG   )r   r   r   r   s       r   rN   zKeyboard.press   s      , Wf--iiW%%%%%%%%%g- 04 7888888888ggcllr   N)__name__
__module____qualname____doc__r   r   strdictr   r0   intr,   r   r*   rG   rJ   r$   rN   r:   r   r   r   r      ss          D,z ,d , , , ,
+ +c +D +3 ++ + + +Z	 	 	 	 	 	)# )$ ) ) ) )VC D    &
D 
D 
D 
D 
D 
D2 2s 2T 2C 22 2 2 2: s T C      r   r   c                       e Zd ZdZdededdfdZddeded	ed
e	ddf
dZ
ddeded	ed
e	ddf
dZdd	ed
e	ddfdZdd	ed
e	ddfdZdS )MousezMouse class.

    The :class:`Mouse` operates in main-frame CSS pixels relative to the
    top-left corner of the viewport.
    r   keyboardr   Nc                 L    || _         || _        d| _        d| _        d| _        d S )Ng        none)r   	_keyboard_x_y_buttonr   r   r\   s      r   r   zMouse.__init__   s)    !r   xyr   r   c           
        K   t          ||          }| j        }| j        }|| _        || _        |                    dd          }t	          d|dz             D ]x}t          || j        |z
  ||z  z  z             }t          || j        |z
  ||z  z  z             }| j                            dd| j        ||| j	        j
        d           d{V  ydS )zMove mouse cursor (dispatches a ``mousemove`` event).

        Options can accepts ``steps`` (int) field. If this ``steps`` option
        specified, Sends intermediate ``mousemove`` events. Defaults to 1.
        stepsr3   Input.dispatchMouseEvent
mouseMoved)r$   buttonrd   re   r%   N)r	   r`   ra   r-   rangeroundr   r.   rb   r_   r   )	r   rd   re   r   r   fromXfromYrg   is	            r   movez
Mouse.move  s      Wf--GQ''q%!)$$ 		 		Aetw1u9==>>Aetw1u9==>>A,##$>$,!^6A A          		 		r   c                 ^  K   t          ||          }|                     ||           d{V  |                     |           d{V  |rF|                    d          r1t	          j        |                    dd          dz             d{V  |                     |           d{V  dS )a  Click button at (``x``, ``y``).

        Shortcut to :meth:`move`, :meth:`down`, and :meth:`up`.

        This method accepts the following options:

        * ``button`` (str): ``left``, ``right``, or ``middle``, defaults to
          ``left``.
        * ``clickCount`` (int): defaults to 1.
        * ``delay`` (int|float): Time to wait between ``mousedown`` and
          ``mouseup`` in milliseconds. Defaults to 0.
        NrL   r   rM   )r	   rp   r0   r-   rO   rP   rG   )r   rd   re   r   r   s        r   clickzMouse.click  s       Wf--ii1ooii          	@w{{7++ 	@-GQ 7 7$ >?????????gggr   c                   K   t          ||          }|                    dd          | _        | j                            dd| j        | j        | j        | j        j        |                    d          pdd           d{V  dS )	a   Press down button (dispatches ``mousedown`` event).

        This method accepts the following options:

        * ``button`` (str): ``left``, ``right``, or ``middle``, defaults to
          ``left``.
        * ``clickCount`` (int): defaults to 1.
        rj   leftrh   mousePressed
clickCountr3   r$   rj   rd   re   r%   rv   N)	r	   r-   rb   r   r.   r`   ra   r_   r   r   r   r   s      r   r0   z
Mouse.down2  s       Wf--{{8V44l :"l2!++l338q=
 =
   	 	 	 	 	 	 	 	 	r   c                   K   t          ||          }d| _        | j                            dd|                    dd          | j        | j        | j        j        |                    d          pdd           d	{V  d	S )
a  Release pressed button (dispatches ``mouseup`` event).

        This method accepts the following options:

        * ``button`` (str): ``left``, ``right``, or ``middle``, defaults to
          ``left``.
        * ``clickCount`` (int): defaults to 1.
        r^   rh   mouseReleasedrj   rt   rv   r3   rw   N)	r	   rb   r   r.   r-   r`   ra   r_   r   rx   s      r   rG   zMouse.upF  s       Wf--l :#kk(F332!++l338q=
 =
   	 	 	 	 	 	 	 	 	r   rR   )rS   rT   rU   rV   r   r   r   floatrX   r   rp   rr   r0   rG   r:   r   r   r[   r[      s        z X $     E e d  %)   0 U u t !&*   * $      (  s t      r   r[   c                   :    e Zd ZdZdededdfdZdededdfd	ZdS )
TouchscreenzTouchscreen class.r   r\   r   Nc                 "    || _         || _        dS )zMake new touchscreen object.N)r   r_   rc   s      r   r   zTouchscreen.__init__^  s    !r   rd   re   c                   K   t          |          t          |          dg}| j                            dd|| j        j        d           d{V  | j                            ddg | j        j        d           d{V  dS )zYTap (``x``, ``y``).

        Dispatches a ``touchstart`` and ``touchend`` event.
        )rd   re   zInput.dispatchTouchEvent
touchStart)r$   touchPointsr%   NtouchEnd)rl   r   r.   r_   r   )r   rd   re   r   s       r   tapzTouchscreen.tapc  s      
 #1XXE!HH556l : &2=
 =
   	 	 	 	 	 	 	
 l :2=
 =
   	 	 	 	 	 	 	 	 	r   )	rS   rT   rU   rV   r   r   r   r{   r   r:   r   r   r}   r}   [  sl        "z "X "$ " " " "
5 U t      r   r}   )rV   rO   typingr   r   r   pyppeteer.connectionr   pyppeteer.errorsr   pyppeteer.us_keyboard_layoutr   pyppeteer.utilr	   r
   objectr   r[   r}   r:   r   r   <module>r      s0   !    + + + + + + + + + + + + + + + + + + + + + + 7 7 7 7 7 7 % % % % % % b b b b bv b b bJa a a a aF a a aH    &     r   