
    ^j_                     v    d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ ddlmZ  G d	 d
ee
e      Zy)    )DictOptional)UnknownMethodException)Self)CanExecuteCommands)CanExecuteScripts)CanRememberExtensionPresence   )MobileCommandc            	           e Zd Zddee   dee   dee   defdZdefdZdde	d	ee	   defd
Z
dde	d	ee	   dee	   defdZdde	d	ee	   dee	   defdZddZy)KeyboardNkey_namekeystrategyreturnc                     d}	 | j                  |      j                  |i |s|r	d|xs |gini        | S # t        $ rN i }|||d<   n|||d<   n|d}||d<   | j                  |      j	                  t
        j                  |       Y | S w xY w)a  Hides the software keyboard on the device.

        In iOS, use `key_name` to press
        a particular key, or `strategy`. In Android, no parameters are used.

        Args:
            key_name: key to press
            key:
            strategy: strategy for closing the keyboard (e.g., `tapOutside`)

        Returns:
            Union['WebDriver', 'Keyboard']: Self instance
        zmobile: hideKeyboardkeyskeyNamer   
tapOutsider   )assert_extension_existsexecute_scriptr   mark_extension_absenceexecuteCommandHIDE_KEYBOARD)selfr   r   r   ext_namedatas         X/home/ubuntu/.local/lib/python3.12/site-packages/appium/webdriver/extensions/keyboard.pyhide_keyboardzKeyboard.hide_keyboard   s     *	W((2AAVSHvx'89RTV  & 
	W-/D#"*Y!U!''D''199':O:OQUV
	Ws   06 ABBc                     d}	 | j                  |      j                  |      S # t        $ r4 | j                  |      j	                  t
        j                        d   cY S w xY w)z|Attempts to detect whether a software keyboard is present

        Returns:
            `True` if keyboard is shown
        zmobile: isKeyboardShownvalue)r   r   r   r   r   r   IS_KEYBOARD_SHOWN)r   r   s     r   is_keyboard_shownzKeyboard.is_keyboard_shown<   sd     -	e//9HHRR% 	e..x8@@AZAZ[\cdd	es   $ :A! A!keycode	metastatec                 (    | j                  ||      S )a  Sends a keycode to the device.

        Android only.
        Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html.

        Args:
            keycode: the keycode to be sent to the device
            metastate: meta information about the keycode being sent

        Returns:
            Union['WebDriver', 'Keyboard']: Self instance
        )r%   r&   )press_keycode)r   r%   r&   s      r   keyeventzKeyboard.keyeventH   s     !!'Y!GG    flagsc                     d}d|i}|||d<   |||d<   	 | j                  |      j                  ||       | S # t        $ r3 | j                  |      j	                  t
        j                  |       Y | S w xY w)a  Sends a keycode to the device.

        Android only. Possible keycodes can be found
        in http://developer.android.com/reference/android/view/KeyEvent.html.

        Args:
            keycode: the keycode to be sent to the device
            metastate: meta information about the keycode being sent
            flags: the set of key event flags

        Returns:
            Union['WebDriver', 'Keyboard']: Self instance
        mobile: pressKeyr%   r&   r+   )r   r   r   r   r   r   PRESS_KEYCODEr   r%   r&   r+   r   argss         r   r(   zKeyboard.press_keycodeW   s     &7#  )D!DM	W((2AA(DQ  & 	W''199':O:OQUV	Ws   !9 8A54A5c                     d}d|i}|||d<   |||d<   	 | j                  |      j                  |i |ddi       | S # t        $ r3 | j                  |      j	                  t
        j                  |       Y | S w xY w)a  Sends a long press of keycode to the device.

        Android only. Possible keycodes can be found in
        http://developer.android.com/reference/android/view/KeyEvent.html.

        Args:
            keycode: the keycode to be sent to the device
            metastate: meta information about the keycode being sent
            flags: the set of key event flags

        Returns:
            Union['WebDriver', 'Keyboard']: Self instance
        r-   r%   r&   r+   isLongPressT)r   r   r   r   r   r   LONG_PRESS_KEYCODEr/   s         r   long_press_keycodezKeyboard.long_press_keycoder   s     &7#  )D!DM
	\((2AA!4  & 	\''199':T:TVZ[	\s   '? 8A;:A;c                    | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j
                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       y )NPOSTz//session/$sessionId/appium/device/hide_keyboardGETz3/session/$sessionId/appium/device/is_keyboard_shownz*/session/$sessionId/appium/device/keyeventz//session/$sessionId/appium/device/press_keycodez4/session/$sessionId/appium/device/long_press_keycode)command_executoradd_commandr   r   r#   	KEY_EVENTr.   r3   )r   s    r   _add_commandszKeyboard._add_commands   s    ))!!=	

 	))%%A	

 	))'*;*;VEqr))!!=	

 	))&&B	
r*   )NNN)N)NN)r   N)__name__
__module____qualname__r   strr   r    boolr$   intr)   r(   r4   r;    r*   r   r   r      s    hsm # aijman z~ @
e4 
eH H H HS Xc] RZ[^R_ ko 6# (3- W_`cWd pt B
r*   r   N)typingr   r   selenium.common.exceptionsr   typing_extensionsr   /appium.protocols.webdriver.can_execute_commandsr   .appium.protocols.webdriver.can_execute_scriptsr   :appium.protocols.webdriver.can_remember_extension_presencer	   mobilecommandr   r   r   rB   r*   r   <module>rJ      s1    " = " N L c 4M
!#46R M
r*   