@@ -2977,11 +2977,20 @@ def _binding_chain(self) -> list[tuple[DOMNode, _Bindings]]:
29772977
29782978 return namespace_bindings
29792979
2980+ def simulate_key (self , key : str ) -> None :
2981+ """Simulate a key press.
2982+
2983+ This will perform the same action as if the user had pressed the key.
2984+
2985+ Args:
2986+ key: Key to simulate. May also be the name of a key, e.g. "space".
2987+ """
2988+ self .call_later (self .check_bindings , key )
2989+
29802990 async def check_bindings (self , key : str , priority : bool = False ) -> bool :
29812991 """Handle a key press.
29822992
2983- This method is used internally by the bindings system, but may be called directly
2984- if you wish to *simulate* a key being pressed.
2993+ This method is used internally by the bindings system.
29852994
29862995 Args:
29872996 key: A key.
@@ -3159,7 +3168,6 @@ async def _dispatch_action(
31593168 params = params ,
31603169 )
31613170
3162- reset_active_message_pump = active_message_pump .set (namespace )
31633171 try :
31643172 private_method = getattr (namespace , f"_action_{ action_name } " , None )
31653173 if callable (private_method ):
@@ -3176,8 +3184,7 @@ async def _dispatch_action(
31763184 except SkipAction :
31773185 # The action method raised this to explicitly not handle the action
31783186 log .system (f"<action> { action_name !r} skipped." )
3179- finally :
3180- active_message_pump .reset (reset_active_message_pump )
3187+
31813188 return False
31823189
31833190 async def _broker_event (
0 commit comments