def init(self, icon, parent=None):
super().init(icon, parent)
self.menu = QtWidgets.QMenu()
self.settings_action = self.menu.addAction('Settings')
self.exit_action = self.menu.addAction('Exit')
self.setContextMenu(self.menu)
self.settings_action.triggered.connect(self.open_settings)
self.exit_action.triggered.connect(self.close_program)
self.settings_dialog = None
self.worker = Worker()
self.worker.start()
self.worker.clipboard_changed.connect(self.handle_clipboard_change)
self.is_typing = False
self.setup_keyboard_listener()
def setup_keyboard_listener(self):
def for_canonical(f):
return lambda k: f(self.l.canonical(k))
self.hotkeys = {
frozenset([keyboard.Key.shift, keyboard.Key.alt, keyboard.Key.ctrl]): self.type_copied_text
}
self.current_keys = set()
self.l = keyboard.Listener(
on_press=for_canonical(self.press_key),
on_release=for_canonical(self.release_key),
)
self.l.start()
def press_key(self, key):
try:
if any([key in self.current_keys for key in self.hotkeys.keys()]):
return
self.current_keys.add(key)
for hotkey in self.hotkeys.keys():
if self.current_keys == hotkey:
self.hotkeyshotkey
except Exception as e:
print(str(e))
pass
def release_key(self, key):
try:
self.current_keys.remove(key)
except KeyError as e:
print(str(e))
pass
def type_copied_text(self):
new_clipboard_content = pyperclip.paste().strip()
if new_clipboard_content:
time.sleep(first_char_delay / 1000)
keyboard_controller = keyboard.Controller()
shift_chars = string.ascii_uppercase + ''.join(
c for c in string.printable if not c.isalnum()
)
for char in new_clipboard_content:
if char in string.printable:
if char in shift_chars:
keyboard_controller.press(keyboard.Key.shift)
time.sleep(shift_delay / 1000)
keyboard_controller.press(char)
keyboard_controller.release(char)
if char in shift_chars:
time.sleep(shift_delay / 1000)
keyboard_controller.release(keyboard.Key.shift)
time.sleep(delay / 1000)
def handle_clipboard_change(self, text):
self.worker.clipboard_content = text
def open_settings(self):
if not self.settings_dialog:
self.settings_dialog = SettingsDialog()
self.settings_dialog.show()
def close_program(self):
self.l.stop()
QtWidgets.QApplication.quit()
Assistant
This script creates a system tray icon in Python that can type out clipboard contents with a specified delay between the characters. You can access its settings by right-clicking the system tray icon and selecting "Settings".
To run the script, make sure you have the following dependencies installed:
pyperclip: pip install pyperclip
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
You will also need to have an icon.png file in the same directory as the script for the system tray icon. Once you have these dependencies installed, run the script using python (e.g., python your_script_name.py). It will create a system tray icon with the ability to type out clipboard contents when you press the specified hotkeys (Shift + Alt + Ctrl by default in this script).
The hotkey can be modified within the script. Here are the main sections you need to know:
delay, first_char_delay, and shift_delay are the three values that can be changed to modify the delays between characters, the delay before the first character starts typing, and the delay in pressing/releasing the shift key if needed.
The type_copied_text function takes the clipboard content and types it out, character by character, simulating keystrokes.
The SettingsDialog class is a popup window that allows you to change the delay, first_char_delay, and shift_delay values, and saves them to a settings file called settings.txt.
The main function sets up the system tray icon, sets the icon image and tooltip, and runs the application. If you have a settings.txt file, the application will read delay values from it.
Note that due to the keyboard emulation nature of the script, it may not work in certain applications or with administrator permissions needed, so make sure to try it in a simple text editor first.
You can customize the script further by adding additional features, such as different hotkeys for different functions or options to clear the clipboard after typing. Make sure to read the documentation for the libraries used in the script for more information on how to extend the functionality.