def direct_callback(self, event):
<EOL>if self.is_replaying:<EOL><INDENT>return True<EOL><DEDENT>if not all(hook(event) for hook in self.blocking_hooks):<EOL><INDENT>return False<EOL><DEDENT>event_type = event.event_type<EOL>scan_code = event.scan_code<EOL>with _pressed_events_lock:<EOL><INDENT>if event_type == KEY_DOWN:<EOL><INDENT>if is_modifier(scan_code): self.active_modifiers.add(scan_code)<EOL>_pressed_events[scan_code] = event<EOL><DEDENT>hotkey = tuple(sorted(_pressed_events))<EOL>if event_type == KEY_UP:<EOL><INDENT>self.active_modifiers.discard(scan_code)<EOL>if scan_code in _pressed_events: del _pressed_events[scan_code]<EOL><DEDENT><DEDENT>for key_hook in self.blocking_keys[scan_code]:<EOL><INDENT>if not key_hook(event):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>accept = True<EOL>if self.blocking_hotkeys:<EOL><INDENT>if self.filtered_modifiers[scan_code]:<EOL><INDENT>origin = '<STR_LIT>'<EOL>modifiers_to_update = set([scan_code])<EOL><DEDENT>else:<EOL><INDENT>modifiers_to_update = self.active_modifiers<EOL>if is_modifier(scan_code):<EOL><INDENT>modifiers_to_update = modifiers_to_update | {scan_code}<EOL><DEDENT>callback_results = [callback(event) for callback in self.blocking_hotkeys[hotkey]]<EOL>if callback_results:<EOL><INDENT>accept = all(callback_results)<EOL>origin = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>origin = '<STR_LIT>'<EOL><DEDENT><DEDENT>for key in sorted(modifiers_to_update):<EOL><INDENT>transition_tuple = (self.modifier_states.get(key, '<STR_LIT>'), event_type, origin)<EOL>should_press, new_accept, new_state = self.transition_table[transition_tuple]<EOL>if should_press: press(key)<EOL>if new_accept is not None: accept = new_accept<EOL>self.modifier_states[key] = new_state<EOL><DEDENT><DEDENT>if accept:<EOL><INDENT>if event_type == KEY_DOWN:<EOL><INDENT>_logically_pressed_keys[scan_code] = event<EOL><DEDENT>elif event_type == KEY_UP and scan_code in _logically_pressed_keys:<EOL><INDENT>del _logically_pressed_keys[scan_code]<EOL><DEDENT><DEDENT>self.queue.put(event)<EOL>return accept<EOL>
This function is called for every OS keyboard event and decides if the
event should be blocked or not, and passes a copy of the event to
other, non-blocking, listeners.

There are two ways to block events: remapped keys, which translate
events by suppressing and re-emitting; and blocked hotkeys, which
suppress specific hotkeys.