
    i^                         d Z ddlZddlZddlZddlZddlZddlmZmZ ddl	m
Z
  G d de      Z G d dej                        Z G d	 d
e      Z G d de      Zy)z
This module contains the base implementation.

The actual interface to keyboard classes is defined here, but the
implementation is located in a platform dependent module.
    N)AbstractListenerprefix)_loggerc                   j    e Zd ZdZg ZddZd Zd Zd Zd Z	d Z
ed	        Zed
        Zed        Zy)KeyCodezg
    A :class:`KeyCode` represents the description of a key code used by the
    operating system.
    Nc           	         || _         |t        j                  |      nd | _        || _        | j                  r^	 t        j                  dt        j                  | j                        z         | _        | j                  r| j                  st        |      d | _        | j                  D ]  }t        | ||j                  |d              ! |rt        |      y # t        $ r d| _        d | _        Y w xY w)Nz
COMBINING F)vksix	text_typecharis_deadunicodedatalookupname	combiningKeyError_PLATFORM_EXTENSIONSsetattrpop
ValueError)selfr	   r   r   kwargskeys         _/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/pynput/keyboard/_base.py__init__zKeyCode.__init__.   s    +/+;CMM$'	<<&!,!3!3 ;#3#3DII#>>"@
 ||DNNtn$!DN,, 	6CD#vzz#t45	6V$$   &$!%&s   :C C43C4c                     | j                   rdt        | j                        z  S | j                  t        | j                        S d| j                  z  S )Nz[%s]z<%d>)r   reprr   r	   r   s    r   __repr__zKeyCode.__repr__E   sC    <<DO++99 		?"DGG##    c                     t        |       S N)r   r   s    r   __str__zKeyCode.__str__M   s    Dzr    c                 @    t         j                        sy j                  @j                  4 j                  j                  k(  xr  j                  j                  k(  S  j                  j                  k(  xr t         fd j                  D              S )NFc              3   P   K   | ]  }t        |      t        |      k(    y wr"   )getattr).0fotherr   s     r   	<genexpr>z!KeyCode.__eq__.<locals>.<genexpr>V   s,      /4 a GE1$55/4s   #&)
isinstance	__class__r   r   r	   allr   )r   r)   s   ``r   __eq__zKeyCode.__eq__P   s    %099 UZZ%;99

*Lt||u}}/LL77ehh& 43 /422/4 ,4 4r    c                 *    t        t        |             S r"   )hashr   r   s    r   __hash__zKeyCode.__hash__Z   s    DJr    c                 <   | j                   st        |       |j                  dk(  s| |k(  r| j                  | j                        S |j                  @t	        j
                  d|j                  | j                  z         }|r| j                  |      S t        |      )a  Applies this dead key to another key and returns the result.

        Joining a dead key with space (``' '``) or itself yields the non-dead
        version of this key, if one exists; for example,
        ``KeyCode.from_dead('~').join(KeyCode.from_char(' '))`` equals
        ``KeyCode.from_char('~')`` and
        ``KeyCode.from_dead('~').join(KeyCode.from_dead('~'))``.

        :param KeyCode key: The key to join with this key.

        :return: a key code

        :raises ValueError: if the keys cannot be joined
         NFC)r   r   r   	from_charr   	normalizer   )r   r   combineds      r   joinzKeyCode.join]   s      ||T"" 88s?dck>>$)),, 88",,4>>)+H ~~h//or    c                      | dd|i|S )zCreates a key from a virtual key code.

        :param vk: The virtual key code.

        :param kwargs: Any other parameters to pass.

        :return: a key code
        r	    r:   )clsr	   r   s      r   from_vkzKeyCode.from_vk   s     #b#F##r    c                      | dd|i|S )znCreates a key from a character.

        :param str char: The character.

        :return: a key code
        r   r:   r:   r;   r   r   s      r   r5   zKeyCode.from_char   s     ''''r    c                      | d|dd|S )zCreates a dead key.

        :param char: The dead key. This should be the unicode character
            representing the stand alone character, such as ``'~'`` for
            *COMBINING TILDE*.

        :return: a key code
        T)r   r   r:   r:   r>   s      r   	from_deadzKeyCode.from_dead   s     5d5f55r    NNF)__name__
__module____qualname____doc__r   r   r   r#   r.   r1   r8   classmethodr<   r5   r@   r:   r    r   r   r   &   sj    
 %.$4  D 	$ 	$ ( ( 	6 	6r    r   c                      e Zd ZdZej                  d      Zej                  d      Zej                  d      Zej                  d      Z	ej                  d      Z
ej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Zej                  d      Z ej                  d      Z!ej                  d      Z"ej                  d      Z#ej                  d      Z$ej                  d      Z%ej                  d      Z&ej                  d      Z'ej                  d      Z(ej                  d      Z)ej                  d      Z*ej                  d      Z+ej                  d      Z,ej                  d      Z-ej                  d      Z.ej                  d      Z/ej                  d      Z0ej                  d      Z1ej                  d      Z2ej                  d      Z3ej                  d      Z4ej                  d      Z5ej                  d      Z6ej                  d      Z7ej                  d      Z8ej                  d      Z9ej                  d      Z:ej                  d      Z;ej                  d      Z<ej                  d      Z=ej                  d      Z>ej                  d      Z?ej                  d      Z@ej                  d      ZAy)Keya(  A class representing various buttons that may not correspond to
    letters. This includes modifier keys and function keys.

    The actual values for these items differ between platforms. Some platforms
    may have additional buttons, but these are guaranteed to be present
    everywhere.
    r   N)BrB   rC   rD   rE   r   r<   altalt_lalt_ralt_gr	backspace	caps_lockcmdcmd_lcmd_rctrlctrl_lctrl_rdeletedownendenterescf1f2f3f4f5f6f7f8f9f10f11f12f13f14f15f16f17f18f19f20homeleft	page_downpage_uprightshiftshift_lshift_rspacetabupmedia_play_pausemedia_volume_mutemedia_volume_downmedia_volume_upmedia_previous
media_nextinsertmenunum_lockpauseprint_screenscroll_lockr:   r    r   rH   rH      s    //!
C OOAE OOAE __QF "I "I
 //!
C
 OOAE
 OOAE ??1D __QF __QF __QF ??1D //!
C OOAE //!
C 
	B		B		B		B		B		B		B		B		B
//!
C
//!
C
//!
C
//!
C
//!
C
//!
C
//!
C
//!
C
//!
C
//!
C
//!
C ??1D ??1D "I ooa G OOAE OOAE ooa G ooa G OOAE //!
C 
	B q)  *  * ooa(O __Q'N #J __QF ??1D q!H OOAE ??1%L //!$Kr    rH   c                      e Zd ZdZeZeZ G d de      Z	 G d de      Z
d Zd Zd Zd	 Zd
 Zej"                  d        Zd Zeej"                  d               Zed        Zed        Zed        Zed        Zd Zd Zd Zd Zy)
ControllerzDA controller for sending virtual keyboard events to the system.
    c                       e Zd ZdZy)Controller.InvalidKeyExceptionzThe exception raised when an invalid ``key`` parameter is passed to
        either :meth:`Controller.press` or :meth:`Controller.release`.

        Its first argument is the ``key`` parameter.
        NrB   rC   rD   rE   r:   r    r   InvalidKeyExceptionr   H  s    	
 	r    r   c                       e Zd ZdZy)$Controller.InvalidCharacterExceptionzThe exception raised when an invalid character is encountered in
        the string passed to :meth:`Controller.type`.

        Its first argument is the index of the character in the string, and the
        second the character.
        Nr   r:   r    r   InvalidCharacterExceptionr   P  s    	 	r    r   c                     t        | j                        | _        t        j                         | _        t               | _        d| _        d | _	        y )NF)
r   r,   _log	threadingRLock_modifiers_lockset
_modifiers
_caps_lock	_dead_keyr   s    r   r   zController.__init__Y  s8    DNN+	(0%r    c                    | j                  |      }|| j                  |      | j                  |d       || j                  j                  j
                  k(  r| j                   | _        |}| j                  r	 | j                  j                  |      }|j                  r|| _        y	 | j                  |d       d| _        y# t        $ r; | j                  | j                  d       | j                  | j                  d       Y rw xY w# | j                  $ rY ||k7  rJ| j                  | j                  d       | j                  | j                  d       | j                  |d       Y d| _        yw xY w)a  Presses a key.

        A key may be either a string of length 1, one of the :class:`Key`
        members or a :class:`KeyCode`.

        Strings will be transformed to :class:`KeyCode` using
        :meth:`KeyCode.char`. Members of :class:`Key` will be translated to
        their :meth:`~Key.value`.

        :param key: The key to press.

        :raises InvalidKeyException: if the key is invalid

        :raises ValueError: if ``key`` is a string, but its length is not ``1``
        NTF)_resolver   _update_modifiers_KeyrN   valuer   r   r8   r   _handler   )r   r   resolvedoriginals       r   presszController.press`  sF     ==%**3//x. tyy**000"&//1DO >>4>>..x8 %DN	-LL4( #  4T^^T2T^^U34 '' 	-8#T^^T2T^^U3Xt,	-s&   ;C +D AD	D	AE43E4c                     | j                  |      }|| j                  |      | j                  |d       |j                  ry| j	                  |d       y)aR  Releases a key.

        A key may be either a string of length 1, one of the :class:`Key`
        members or a :class:`KeyCode`.

        Strings will be transformed to :class:`KeyCode` using
        :meth:`KeyCode.char`. Members of :class:`Key` will be translated to
        their :meth:`~Key.value`.

        :param key: The key to release. If this is a string, it is passed to
            :meth:`touches` and the returned releases are used.

        :raises InvalidKeyException: if the key is invalid

        :raises ValueError: if ``key`` is a string, but its length is not ``1``
        NF)r   r   r   r   r   )r   r   r   s      r   releasezController.release  sU    " ==%**3//x/ Xu%r    c                 H    | j                  |       | j                  |       y)aS  Presses and releases a key.

        This is equivalent to the following code::

            controller.press(key)
            controller.release(key)

        :param key: The key to press.

        :raises InvalidKeyException: if the key is invalid

        :raises ValueError: if ``key`` is a string, but its length is not ``1``
        Nr   r   r   r   s     r   tapzController.tap  s     	

3Sr    c                 N    |r| j                  |       y| j                  |       y)a  Calls either :meth:`press` or :meth:`release` depending on the value
        of ``is_press``.

        :param key: The key to press or release.

        :param bool is_press: Whether to press the key.

        :raises InvalidKeyException: if the key is invalid
        Nr   r   r   is_presss      r   touchzController.touch  s     JJsOLLr    c              '      K   |D ]  }| j                  |        	 d t        |      D ]  }| j                  |        y# t        |      D ]  }| j                  |        w xY ww)zaExecutes a block with some keys pressed.

        :param keys: The keys to keep pressed.
        N)r   reversedr   )r   argsr   s      r   pressedzController.pressed  sh       	CJJsO		"~ "S!"x~ "S!"s   A(A "A(#A%%A(c                     ddl m} t        |      D ]:  \  }}|j                  ||      }	 | j	                  |       | j                  |       < y# t        | j                  f$ r | j                  ||      w xY w)a  Types a string.

        This method will send all key presses and releases necessary to type
        all characters in the string.

        :param str string: The string to type.

        :raises InvalidCharacterException: if an untypable character is
            encountered
           )_CONTROL_CODESN)	 r   	enumerategetr   r   r   r   r   )r   stringr   i	characterr   s         r   typezController.type  s     	%%f- 	CLAy $$Y	:CC

3S!		C  8 89 C44Q	BBCs   "A(A8c              #       K    j                   5  t         fd j                  D               ddd       y# 1 sw Y   yxY ww)a  The currently pressed modifier keys.

        Please note that this reflects only the internal state of this
        controller, and not the state of the operating system keyboard buffer.
        This property cannot be used to determine whether a key is physically
        pressed.

        Only the generic modifiers will be set; when pressing either
        :attr:`Key.shift_l`, :attr:`Key.shift_r` or :attr:`Key.shift`, only
        :attr:`Key.shift` will be present.

        Use this property within a context block thus::

            with controller.modifiers as modifiers:
                with_block()

        This ensures that the modifiers cannot be modified by another thread.
        c              3   @   K   | ]  }j                  |        y wr"   )_as_modifier)r'   modifierr   s     r   r*   z'Controller.modifiers.<locals>.<genexpr>  s$      1 !!(+1s   N)r   r   r   r   s   `r   	modifierszController.modifiers  sD     * !! 	1 1 $1 1 1	1 	1 	1s   A!:	AAAc                 v    | j                   5 }| j                  j                  |v cddd       S # 1 sw Y   yxY w)zWhether any *alt* key is pressed.

        Please note that this reflects only the internal state of this
        controller. See :attr:`modifiers` for more information.
        N)r   r   rI   r   r   s     r   alt_pressedzController.alt_pressed  s2     ^^ 	.y99==I-	. 	. 	.   /8c                 v    | j                   5 }| j                  j                  |v cddd       S # 1 sw Y   yxY w)zWhether *altgr* is pressed.

        Please note that this reflects only the internal state of this
        controller. See :attr:`modifiers` for more information.
        N)r   r   rL   r   s     r   alt_gr_pressedzController.alt_gr_pressed  s4     ^^ 	1y99##y0	1 	1 	1r   c                 v    | j                   5 }| j                  j                  |v cddd       S # 1 sw Y   yxY w)zWhether any *ctrl* key is pressed.

        Please note that this reflects only the internal state of this
        controller. See :attr:`modifiers` for more information.
        N)r   r   rR   r   s     r   ctrl_pressedzController.ctrl_pressed  s2     ^^ 	/y99>>Y.	/ 	/ 	/r   c                     | j                   ry| j                  5 }| j                  j                  |v cddd       S # 1 sw Y   yxY w)zWhether any *shift* key is pressed, or *caps lock* is toggled.

        Please note that this reflects only the internal state of this
        controller. See :attr:`modifiers` for more information.
        TN)r   r   r   rs   r   s     r   shift_pressedzController.shift_pressed)  s<     ??^^ 	0y99??i/	0 	0 	0s	   <Ac                    |d | j                   D        v r|j                  S t        |t        j                        r4t        |      dk7  rt        |      | j                  j                  |      S t        || j                        rO|j                  A| j                  r5| j                  |j                  |j                  j                               S |S y)a  Resolves a key to a :class:`KeyCode` instance.

        This method will convert any key representing a character to uppercase
        if a shift modifier is active.

        :param key: The key to resolve.

        :return: a key code, or ``None`` if it cannot be resolved
        c              3       K   | ]  }|  y wr"   r:   )r'   ks     r   r*   z&Controller._resolve.<locals>.<genexpr>A  s     (1(s   r   N)r	   r   )r   r   r+   r
   string_typeslenr   _KeyCoder5   r   r   r	   upperr   s     r   r   zController._resolve6  s     (dii((99 c3++,3x1} o%==**3// c4==)xx#(:(:}}SXX^^5E}FF
	 *r    c                     | j                  |      rP| j                  5  |r| j                  j                  |       n	 | j                  j	                  |       ddd       yy# t
        $ r Y w xY w# 1 sw Y   yxY w)zUpdates the current modifier list.

        If ``key`` is not a modifier, no action is taken.

        :param key: The key being pressed or released.
        N)r   r   r   addremover   r   s      r   r   zController._update_modifiersQ  sz     S!%% OO'',..s3  " $  s(   A2A##	A/,A2.A//A22A;c                 2    ddl m} |j                  |d      S )af  Returns a key as the modifier used internally if defined.

        This method will convert values like :attr:`Key.alt_r.value` and
        :attr:`Key.shift_l.value` to :attr:`Key.alt` and :attr:`Key.shift`.

        :param key: The possible modifier key.

        :return: the base modifier key, or ``None`` if ``key`` is not a
            modifier
        r   )_NORMAL_MODIFIERSN)r   r   r   )r   r   r   s      r   r   zController._as_modifierc  s     	( $$S$//r    c                     t               )zThe platform implementation of the actual emitting of keyboard
        events.

        This is a platform dependent implementation.

        :param Key key: The key to handle.

        :param bool is_press: Whether this is a key press event.
        )NotImplementedErrorr   s      r   r   zController._handleq  s     "##r    N)rB   rC   rD   rE   r   r   rH   r   	Exceptionr   r   r   r   r   r   r   
contextlibcontextmanagerr   r   propertyr   r   r   r   r   r   r   r   r   r:   r    r   r   r   ?  s     H Di I /b&8" " "C* 1  10 . . 1 1 / / 
0 
06$0
$r    r   c                   *     e Zd ZdZd fd	Zd Z xZS )Listenera  A listener for keyboard events.

    Instances of this class can be used as context managers. This is equivalent
    to the following code::

        listener.start()
        try:
            listener.wait()
            with_statements()
        finally:
            listener.stop()

    This class inherits from :class:`threading.Thread` and supports all its
    methods. It will set :attr:`daemon` to ``True`` when created.

    All callback arguments are optional; a callback may take less arguments
    than actually passed, but not more, unless they are optional.

    :param callable on_press: The callback to call when a button is pressed.

        It will be called with the arguments ``(key, injected)``, where ``key``
        is a :class:`KeyCode`, a :class:`Key` or ``None`` if the key is
        unknown, and ``injected`` whether the event was injected and thus not
        generated by an actual input device.

        Please note that not all backends support ``injected`` and will always
        set it to ``False``.

    :param callable on_release: The callback to call when a button is released.

        It will be called with the arguments ``(key, injected)``, where ``key``
        is a :class:`KeyCode`, a :class:`Key` or ``None`` if the key is
        unknown, and ``injected`` whether the event was injected and thus not
        generated by an actual input device.

        Please note that not all backends support ``injected`` and will always
        set it to ``False``.

    :param bool suppress: Whether to suppress events. Setting this to ``True``
        will prevent the input events from being passed to the rest of the
        system.

    :param kwargs: Any non-standard platform dependent options. These should be
        prefixed with the platform name thus: ``darwin_``, ``uinput_``,
        ``xorg_`` or ``win32_``.

        Supported values are:

        ``darwin_intercept``
            A callable taking the arguments ``(event_type, event)``, where
            ``event_type`` is ``Quartz.kCGEventKeyDown`` or
            ``Quartz.kCGEventKeyUp``, and ``event`` is a ``CGEventRef``.

            This callable can freely modify the event using functions like
            ``Quartz.CGEventSetIntegerValueField``. If this callable does not
            return the event, the event is suppressed system wide.

        ``uinput_device_paths``
            A list of device paths.

            If this is specified, *pynput* will limit the number of devices
            checked for the capabilities needed to those passed, otherwise all
            system devices will be used. Passing this might be required if an
            incorrect device is chosen.

        ``win32_event_filter``
            A callable taking the arguments ``(msg, data)``, where ``msg`` is
            the current message, and ``data`` associated data as a
            `KBDLLHOOKSTRUCT <https://docs.microsoft.com/en-gb/windows/win32/api/winuser/ns-winuser-kbdllhookstruct>`_.

            If this callback returns ``False``, the event will not be
            propagated to the listener callback.

            If ``self.suppress_event()`` is called, the event is suppressed
            system wide.
    c                 r   t        | j                        | _        t        t        | j                        }|j                         D ci c]%  \  }}|j                  |      r|t        |      d  |' c}}| _        t        t        | +  | j                  |d      | j                  |d      |       y c c}}w )N   )on_press
on_releasesuppress)r   r,   r   r   r   items
startswithr   _optionssuperr   _wrap)	r   r   r   r   r   option_prefixr   r   r,   s	           r   r   zListener.__init__  s    DNN+	x8 %lln.U~~m, M"#$e+. 	h&ZZ!,zz*a0 	' 		.s   	*B3c                 |   ddl m}m}m} t	        ||      r5|j
                  )|j                  |j
                  j                               S t	        ||      r|j                  |v r||j                     S t	        ||      r;|j                  j                  %|j                  |j                  j                        S |S )a  Performs normalisation of a key.

        This method attempts to convert key events to their canonical form, so
        that events will equal regardless of modifier state.

        This method will convert upper case keys to lower case keys, convert
        any modifiers with a right and left version to the same value, and may
        slow perform additional platform dependent normalisation.

        :param key: The key to normalise.
        :type key: Key or KeyCode

        :return: a key
        :rtype: Key or KeyCode
        r   )rH   r   r   )pynput.keyboardrH   r   r   r+   r   r5   lowerr   r	   r<   )r   r   rH   r   r   s        r   	canonicalzListener.canonical  s      	DCc7#(<$$SXX^^%566S!cii3D&D$SYY//S!ciill&>??399<<00Jr    rA   )rB   rC   rD   rE   r   r   __classcell__)r,   s   @r   r   r     s    KXr    r   )rE   r   enumr   r   r
   pynput._utilr   r   pynputr   objectr   EnumrH   r   r   r:   r    r   <module>r      sa   "     
 1 y6f y6xZ%$)) Z%z|$ |$@
s sr    