@@ -1698,9 +1698,10 @@ def wrapper(event, *args, **kwargs):
16981698 def _binding_name (callback_or_cmd ):
16991699 return 'py_kb_{:016x}' .format (hash (callback_or_cmd )& 0xffffffffffffffff )
17001700
1701- def on_key_press (self , keydef , mode = 'force' ):
1701+ def on_key_press (self , keydef , mode = 'force' , repetition = False ):
17021702 """Function decorator to register a simplified key binding. The callback is called whenever the key given is
1703- *pressed*.
1703+ *pressed*. When the ``repetition=True`` is passed, the callback is called again repeatedly while the key is held
1704+ down.
17041705
17051706 To unregister the callback function, you can call its ``unregister_mpv_key_bindings`` attribute::
17061707
@@ -1720,17 +1721,20 @@ def binding():
17201721 def register (fun ):
17211722 @self .key_binding (keydef , mode )
17221723 @wraps (fun )
1723- def wrapper (state = 'p-' , name = None , char = None ):
1724- if state [0 ] in ('d' , 'p' ):
1724+ def wrapper (state = 'p-' , name = None , char = None , * _ ):
1725+ if state [0 ] in ('d' , 'p' ) or ( repetition and state [ 0 ] == 'r' ) :
17251726 fun ()
17261727 return wrapper
17271728 return register
17281729
17291730 def key_binding (self , keydef , mode = 'force' ):
17301731 """Function decorator to register a low-level key binding.
17311732
1732- The callback function signature is ``fun(key_state, key_name)`` where ``key_state`` is either ``'U'`` for "key
1733- up" or ``'D'`` for "key down".
1733+ The callback function signature is ``fun(key_state, key_name, key_char, scale, arg)``.
1734+
1735+ The key_state contains up to three chars, corresponding to the regex ``[udr]([m-][c-]?)?``. ``[udr]`` means
1736+ "key up", "key down", or "repetition" for when the key is held down. "m" indicates mouse events, and "c"
1737+ indicates key up events resulting from a logical cancellation. For details check out the mpv man page.
17341738
17351739 The keydef format is: ``[Shift+][Ctrl+][Alt+][Meta+]<key>`` where ``<key>`` is either the literal character the
17361740 key produces (ASCII or Unicode character), or a symbolic name (as printed by ``mpv --input-keylist``).
@@ -1785,12 +1789,12 @@ def register_key_binding(self, keydef, callback_or_cmd, mode='force'):
17851789 raise TypeError ('register_key_binding expects either an str with an mpv command or a python callable.' )
17861790 self .command ('enable-section' , binding_name , 'allow-hide-cursor+allow-vo-dragging' )
17871791
1788- def _handle_key_binding_message (self , binding_name , key_state , key_name = None , key_char = None ):
1792+ def _handle_key_binding_message (self , binding_name , key_state , key_name = None , key_char = None , scale = None , arg = None , * _ ):
17891793 binding_name = binding_name .decode ('utf-8' )
17901794 key_state = key_state .decode ('utf-8' )
17911795 key_name = key_name .decode ('utf-8' ) if key_name is not None else None
17921796 key_char = key_char .decode ('utf-8' ) if key_char is not None else None
1793- self ._key_binding_handlers [binding_name ](key_state , key_name , key_char )
1797+ self ._key_binding_handlers [binding_name ](key_state , key_name , key_char , scale , arg )
17941798
17951799 def unregister_key_binding (self , keydef ):
17961800 """Unregister a key binding by keydef."""
0 commit comments