Код: Выделить всё
def low_level_keyboard_handler(nCode, wParam, lParam):
global custom_paste_enabled_blocking_os_paste
global is_pressed_ctrl_v
if nCode >= 0: # Only handle valid events
kbd_struct = ctypes.cast(lParam, ctypes.POINTER(KBDLLHOOKSTRUCT)).contents
vk_code = kbd_struct.vkCode # Extract virtual key code
isCtrlPressed = win32api.GetAsyncKeyState(win32con.VK_CONTROL) < 0 # Check Ctrl state
# logging.info(f"Key event: {vk_code}, wParam: {wParam}")
if wParam == 0x100: # WM_KEYDOWN
if vk_code == VK_V and isCtrlPressed:
logging.info("Ctrl+V pressed.")
if custom_paste_enabled_blocking_os_paste:
logging.info("Blocked OS Ctrl+V")
is_pressed_ctrl_v = True
logging.info(f"Ctrl+V pressed: {is_pressed_ctrl_v}")
ctrl_v_event.set()
logging.info(f"ctrl_v_event: {ctrl_v_event.is_set()}")
return 1
if vk_code == VK_F9:
logging.info("F9 pressed. Toggling clipboard scroller.")
toggle_clipboard_scroller()
if wParam == 0x101: # WM_KEYUP
if vk_code == VK_V:
is_pressed_ctrl_v = False
logging.info(f"Ctrl+V pressed: {is_pressed_ctrl_v}")
ctrl_v_event.clear()
logging.info(f"ctrl_v_event: {ctrl_v_event.is_set()}")
return 1
return ctypes.windll.user32.CallNextHookEx(hHook, nCode, wParam, lParam)
Код: Выделить всё
def scroll_clipboard_history(self, direction):
if custom_paste_enabled_blocking_os_paste and is_pressed_ctrl_v and not toggle_flag.is_set() and ctrl_v_event.is_set():
with self.lock:
self.previous_index = self.current_index
logging.info(f"Scrolling clipboard history: {direction}")
logging.info(f"Scrolling out of previous index: {self.clipboard_history[self.previous_index]}")
if direction == "up":
self.current_index = max(0, self.current_index - 1)
elif direction == "down":
self.current_index = min(len(self.clipboard_history) - 1, self.current_index + 1)
logging.info(f"Scrolled to entry: {self.clipboard_history[self.current_index]}")
self.paste_selection()
def paste_selection(self):
if custom_paste_enabled_blocking_os_paste and is_pressed_ctrl_v and not toggle_flag.is_set() and ctrl_v_event.is_set():
with self.lock:
if self.current_index != self.previous_index and 0
Подробнее здесь: [url]https://stackoverflow.com/questions/79276231/trying-and-failing-to-paste-anything-with-my-own-implemented-pasting-logic-while[/url]