Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: win_shortcuts_automation.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- :: Welcome to Windows Shortcuts Automation ::
- - This script is your gateway to unlocking the true potential of your Windows experience!
- - Say goodbye to repetitive tasks and hello to seamless automation with Python.
- - Whether you're a seasoned user looking to supercharge your workflow or a curious beginner eager to explore the possibilities,
- this script is here to revolutionize the way you interact with your Windows system.
- Features:
- - Harness the power of Python to automate a plethora of Windows shortcuts effortlessly.
- - Enjoy a user-friendly interface that simplifies the selection and execution of shortcuts.
- - Customize your experience by crafting your own personalized hotkeys to suit your unique needs.
- Prerequisites:
- - Python 3.x
- - The following modules must be installed:
- - pygetwindow
- - PyAutoGUI
- - keyboard
- - json
- - os
- How to Use:
- 1. Ensure you have Python 3.x installed on your system.
- 2. Install the required modules using pip:
- 'pip install pyautogui pygetwindow keyboard json'
- 3. Run the script and embark on an adventure of Windows automation!
- - Simply follow the on-screen prompts to select and execute your desired shortcuts.
- Additional Insights:
- - Certain shortcuts may necessitate additional permissions or configurations, so be sure to grant any required permissions.
- - Delve into the realm of Windows automation with confidence and unleash your productivity like never before!
- """
- # Get Essential Imports
- import json
- import keyboard
- import os
- import pyautogui
- import pygetwindow as gw
- def select_program():
- """
- Function for program selection via file explorer navigation
- """
- os.system("explorer C:\\Program Files (x86)")
- # Predefined hotkeys
- PREDEFINED_HOTKEYS = {
- "open_start_menu": ['win'],
- "open_secret_start_menu": ['win', 'x'],
- "cycle_through_taskbar": ['win', 't'],
- "go_to_nth_application": ['win', '[n]'],
- "show_all_running_applications": ['win', 'tab'],
- "show_hide_desktop": ['win', 'd'],
- "minimize_all_windows": ['ctrl', 'm'],
- "temporary_show_desktop": ['win', ','],
- "magnify_screen_content": ['win', 'plus'],
- "maximize_window": ['win', 'up'],
- "maximize_window_vertically": ['win', 'shift', 'up'],
- "move_window_to_left_monitor": ['custom'],
- "move_window_to_right_monitor": ['custom'],
- "take_rectangular_screenshot": ['win', 'shift', 's'],
- "take_full_screenshot": ['win', 'printscreen'],
- "create_new_virtual_desktop": ['win', 'ctrl', 'd'],
- "move_between_virtual_desktops_left": ['win', 'ctrl', 'left'],
- "move_between_virtual_desktops_right": ['win', 'ctrl', 'right'],
- "close_current_virtual_desktop": ['win', 'ctrl', 'f4'],
- "open_action_center": ['win', 'a'],
- "open_search": ['win', 's'],
- "open_new_edge_tab": ['win', 'c'],
- "open_windows_settings": ['win', 'i'],
- "connect_sidebar": ['win', 'k'],
- "use_voice_typing": ['win', 'h'],
- "lock_computer": ['win', 'l'],
- "lock_screen_orientation": ['win', 'o'],
- "open_presentation_sidebar": ['win', 'p'],
- "open_ease_of_access_center": ['win', 'u'],
- "select_from_clipboard_history": ['win', 'v'],
- "set_focus_to_notification_area": ['win', 'b'],
- "open_emoji_panel": ['win', '.'],
- "start_stop_narrator": ['win', 'ctrl', 'enter'],
- "quick_language_list": ['win', 'space'],
- "open_system_control_panel": ['win', 'pause'],
- "start_task_manager": ['ctrl', 'shift', 'esc'],
- "start_on_screen_keyboard": ['ctrl', 'win', 'o'],
- "open_office_application_w": ['ctrl', 'shift', 'alt', 'win', 'w'],
- "open_office_application_p": ['ctrl', 'shift', 'alt', 'win', 'p'],
- "open_office_application_x": ['ctrl', 'shift', 'alt', 'win', 'x'],
- "open_office_application_o": ['ctrl', 'shift', 'alt', 'win', 'o'],
- "open_office_application_t": ['ctrl', 'shift', 'alt', 'win', 't'],
- "open_office_application_d": ['ctrl', 'shift', 'alt', 'win', 'd'],
- "open_office_application_n": ['ctrl', 'shift', 'alt', 'win', 'n'],
- "open_office_application_l": ['ctrl', 'shift', 'alt', 'win', 'l'],
- "open_office_application_y": ['ctrl', 'shift', 'alt', 'win', 'y'],
- "open_calculator": ['win', 'r', 'c', 'a', 'l', 'c', 'enter']
- }
- """ :: Function definitions for shortcuts :: """
- def open_start_menu():
- """
- Opens the Start Menu.
- """
- pyautogui.hotkey('win')
- def open_secret_start_menu():
- """
- Opens the secret Start Menu.
- """
- pyautogui.hotkey('win', 'x')
- def cycle_through_taskbar():
- """
- Cycles through the items on the taskbar.
- """
- pyautogui.hotkey('win', 't')
- def go_to_nth_application():
- """
- Goes to the nth application on the taskbar.
- """
- n = input("Enter application number (1-9): ")
- pyautogui.hotkey('win', n)
- def show_all_running_applications():
- """
- Shows all running applications using Task View.
- """
- pyautogui.hotkey('win', 'tab')
- def show_hide_desktop():
- """
- Shows or hides the desktop.
- """
- pyautogui.hotkey('win', 'd')
- def minimize_all_windows():
- """
- Minimizes all open windows.
- """
- pyautogui.hotkey('ctrl', 'm')
- def temporary_show_desktop():
- """
- Temporarily shows the desktop.
- """
- pyautogui.hotkey('win', ',')
- def magnify_screen_content():
- """
- Magnifies the content on the screen.
- """
- pyautogui.hotkey('win', 'plus')
- def maximize_window():
- """
- Maximizes the current window.
- """
- pyautogui.hotkey('win', 'up')
- def maximize_window_vertically():
- """
- Maximizes the height of the current window.
- """
- pyautogui.hotkey('win', 'shift', 'up')
- def move_window_to_left_monitor():
- """
- Moves the current window to the left monitor.
- """
- active_window = gw.getActiveWindow()
- if active_window:
- active_window.moveTo(0, active_window.top)
- def move_window_to_right_monitor():
- """
- Moves the current window to the right monitor.
- """
- active_window = gw.getActiveWindow()
- if active_window:
- screen_width, _ = pyautogui.size()
- window_width, _ = active_window.size
- new_left_position = min(screen_width - window_width, active_window.left + screen_width)
- active_window.move(new_left_position, active_window.top)
- def take_rectangular_screenshot():
- """
- Takes a rectangular screenshot.
- """
- pyautogui.hotkey('win', 'shift', 's')
- def take_full_screenshot():
- """
- Takes a full screenshot.
- """
- pyautogui.hotkey('win', 'printscreen')
- def create_new_virtual_desktop():
- """
- Creates a new virtual desktop.
- """
- pyautogui.hotkey('win', 'ctrl', 'd')
- def move_between_virtual_desktops(direction):
- """
- Moves between virtual desktops.
- Args:
- direction (str): The direction to move between desktops. Can be 'left' or 'right'.
- """
- pyautogui.hotkey('win', 'ctrl', direction)
- def close_current_virtual_desktop():
- """
- Closes the current virtual desktop.
- """
- pyautogui.hotkey('win', 'ctrl', 'f4')
- def open_action_center():
- """
- Opens the Action Center.
- """
- pyautogui.hotkey('win', 'a')
- def open_search():
- """
- Opens the search menu.
- """
- pyautogui.hotkey('win', 's')
- def open_new_edge_tab():
- """
- Opens a new tab in Microsoft Edge.
- """
- pyautogui.hotkey('win', 'c')
- def open_windows_settings():
- """
- Opens the Windows Settings.
- """
- pyautogui.hotkey('win', 'i')
- def connect_sidebar():
- """
- Connects the sidebar.
- """
- pyautogui.hotkey('win', 'k')
- def use_voice_typing():
- """
- Starts voice typing.
- """
- pyautogui.hotkey('win', 'h')
- def lock_computer():
- """
- Locks the computer.
- """
- pyautogui.hotkey('win', 'l')
- def lock_screen_orientation():
- """
- Locks the screen orientation.
- """
- pyautogui.hotkey('win', 'o')
- def open_presentation_sidebar():
- """
- Opens the presentation sidebar.
- """
- pyautogui.hotkey('win', 'p')
- def open_ease_of_access_center():
- """
- Opens the Ease of Access Center.
- """
- pyautogui.hotkey('win', 'u')
- def select_from_clipboard_history():
- """
- Selects from the clipboard history.
- """
- pyautogui.hotkey('win', 'v')
- def set_focus_to_notification_area():
- """
- Sets focus to the notification area.
- """
- pyautogui.hotkey('win', 'b')
- def open_emoji_panel():
- """
- Opens the emoji panel.
- """
- pyautogui.hotkey('win', '.')
- def start_stop_narrator():
- """
- Starts or stops the narrator.
- """
- pyautogui.hotkey('win', 'ctrl', 'enter')
- def quick_language_list():
- """
- Opens the quick language list.
- """
- pyautogui.hotkey('win', 'space')
- def open_system_control_panel():
- """
- Opens the system control panel.
- """
- pyautogui.hotkey('win', 'pause')
- def start_task_manager():
- """
- Starts the Task Manager.
- """
- pyautogui.hotkey('ctrl', 'shift', 'esc')
- def start_on_screen_keyboard():
- """
- Starts the on-screen keyboard.
- """
- pyautogui.hotkey('ctrl', 'win', 'o')
- def open_calculator():
- """
- Opens the Windows Calculator.
- """
- pyautogui.hotkey('win', 'r')
- pyautogui.typewrite('calc')
- pyautogui.press('enter')
- def open_office_application(app):
- """
- Opens an Office application.
- Args:
- app (str): The abbreviation of the Office application to open.
- 'w' for Word
- 'p' for PowerPoint
- 'x' for Excel
- 'o' for Outlook
- 't' for Teams
- 'd' for OneDrive
- 'n' for OneNote
- 'l' for LinkedIn
- 'y' for Yammer
- """
- pyautogui.hotkey('ctrl', 'shift', 'alt', 'win', app)
- def load_hotkeys():
- """
- Load the hotkey configuration from the 'hotkeys.json' file.
- Returns:
- dict: A dictionary containing the loaded hotkey configuration.
- """
- try:
- with open("hotkeys.json", "r") as file:
- hotkeys = json.load(file)
- except FileNotFoundError:
- hotkeys = {"known": PREDEFINED_HOTKEYS, "custom": {}}
- return hotkeys
- def save_hotkeys(hotkeys):
- """
- Save the hotkey configuration to the 'hotkeys.json' file.
- Args:
- hotkeys (dict): A dictionary containing the hotkey configuration to be saved.
- """
- with open("hotkeys.json", "w") as file:
- json.dump(hotkeys, file, indent=4)
- def get_hotkey_input():
- """
- Get input for a custom hotkey sequence from the user.
- Returns:
- list: A list representing the custom hotkey sequence.
- """
- print("Press your custom hotkey sequence. Press 'Esc' to finish input.")
- hotkey = []
- modifiers = set() # Track pressed modifier keys
- while True:
- key = keyboard.read_event(suppress=True)
- if key.event_type == "down":
- if key.name == "esc":
- break
- elif key.name in ["shift", "ctrl", "alt", "win"]:
- modifiers.add(key.name)
- else:
- hotkey.append("+".join(modifiers))
- hotkey.append(key.name)
- modifiers.clear()
- print("Current input:", "+".join(hotkey))
- return hotkey
- def create_custom_hotkey():
- """
- Create a custom hotkey and save it to the hotkey configuration.
- """
- hotkeys = load_hotkeys()
- hotkey = get_hotkey_input()
- hotkey_str = "+".join(hotkey)
- print("Your input:", hotkey_str)
- if hotkey_str in hotkeys["known"]:
- print(f"The hotkey '{hotkey_str}' already exists for {hotkeys['known'][hotkey_str]}.")
- print("Do you want to overwrite it or go back? (1 to Overwrite, 0 to Go Back)")
- choice = input().strip()
- if choice == '0':
- return
- elif hotkey_str in hotkeys["custom"]:
- print(f"The hotkey '{hotkey_str}' already exists for {hotkeys['custom'][hotkey_str]}.")
- print("Do you want to overwrite it or go back? (1 to Overwrite, 0 to Go Back)")
- choice = input().strip()
- if choice == '0':
- return
- select_program() # Open file explorer
- program_path = input("Enter the program path or select the program file: ").strip()
- hotkeys["custom"][hotkey_str] = program_path
- save_hotkeys(hotkeys)
- # Dictionary mapping shortcut numbers to functions
- shortcut_groups = {
- "General Shortcuts": {
- "1": open_start_menu,
- "2": open_secret_start_menu,
- "3": cycle_through_taskbar,
- "4": go_to_nth_application,
- "5": show_all_running_applications,
- "6": show_hide_desktop,
- "7": minimize_all_windows,
- "8": temporary_show_desktop,
- "9": magnify_screen_content,
- "10": maximize_window,
- "11": maximize_window_vertically,
- "12": move_window_to_left_monitor,
- "13": move_window_to_right_monitor,
- "14": take_rectangular_screenshot,
- "15": take_full_screenshot,
- "16": open_calculator
- },
- "Virtual Desktop Shortcuts": {
- "17": create_new_virtual_desktop,
- "18": lambda: move_between_virtual_desktops("left"),
- "19": lambda: move_between_virtual_desktops("right"),
- "20": close_current_virtual_desktop
- },
- "System Shortcuts": {
- "21": open_action_center,
- "22": open_search,
- "23": open_new_edge_tab,
- "24": open_windows_settings,
- "25": connect_sidebar,
- "26": use_voice_typing,
- "27": lock_computer,
- "28": lock_screen_orientation
- },
- "Accessibility Shortcuts": {
- "29": open_presentation_sidebar,
- "30": open_ease_of_access_center,
- "31": select_from_clipboard_history,
- "32": set_focus_to_notification_area,
- "33": open_emoji_panel,
- "34": start_stop_narrator,
- "35": quick_language_list,
- "36": open_system_control_panel,
- "37": start_task_manager,
- "38": start_on_screen_keyboard
- },
- "Office Application Shortcuts": {
- "39": lambda: open_office_application("w"), # Word
- "40": lambda: open_office_application("p"), # PowerPoint
- "41": lambda: open_office_application("x"), # Excel
- "42": lambda: open_office_application("o"), # Outlook
- "43": lambda: open_office_application("t"), # Teams
- "44": lambda: open_office_application("d"), # OneDrive
- "45": lambda: open_office_application("n"), # OneNote
- "46": lambda: open_office_application("l"), # LinkedIn
- "47": lambda: open_office_application("y") # Yammer
- },
- "Create Custom Hotkey": { # "Create Custom Hotkey" Group
- "48": create_custom_hotkey
- }
- }
- # Descriptive names for office application functions
- descriptive_names = {
- "17": "Move Left (Virtual Desktop)", # Moves to the virtual desktop to the Left
- "18": "Move Right (Virtual Desktop)", # Moves to the virtual desktop to the Right
- "38": "Open Word",
- "39": "Open PowerPoint",
- "40": "Open Excel",
- "41": "Open Outlook",
- "42": "Open Teams",
- "43": "Open OneDrive",
- "44": "Open OneNote",
- "45": "Open LinkedIn",
- "46": "Open Yammer"
- }
- # Main function to execute shortcuts
- def main():
- while True:
- print("\nHotkey Main Menu:\n")
- for index, group in enumerate(shortcut_groups.keys(), start=1):
- print(f"{index:2}: {group}")
- print(" 0: Exit")
- choice = input("\nEnter the number of the group you want to explore: ")
- if choice == '0':
- print("\nExiting Program...\tGoodBye!\n") # Added exit message
- break
- elif choice.isdigit() and int(choice) in range(1, len(shortcut_groups) + 1):
- group_index = int(choice) - 1
- selected_group = list(shortcut_groups.keys())[group_index]
- selected_shortcuts = shortcut_groups[selected_group]
- print(f"\n{selected_group} Options:\n")
- for index, (key, value) in enumerate(selected_shortcuts.items(), start=1):
- if key in descriptive_names: # Check if the key has a descriptive name (Not Lambda)
- name = descriptive_names[key]
- else:
- if callable(value): # Check if it's a function or lambda
- if hasattr(value, '__name__'): # For regular functions
- name = value.__name__.replace('_', ' ')
- else: # For lambda functions
- name = "Custom Function"
- else:
- name = value.__class__.__name__ # Get class name for non-function values
- print(f"{index:2}: {name}")
- while True:
- sub_choice = input("\nEnter the number of the shortcut you want to execute (0 to go back): ")
- if sub_choice == '0':
- break
- elif sub_choice.isdigit() and int(sub_choice) in range(1, len(selected_shortcuts) + 1):
- selected_index = int(sub_choice) - 1
- selected_key = list(selected_shortcuts.keys())[selected_index]
- selected_shortcut = selected_shortcuts[selected_key]
- if callable(selected_shortcut):
- try:
- selected_shortcut()
- except Exception as e:
- print(f"An error occurred: {e}")
- else:
- print("Invalid choice. Please enter a valid number")
- else:
- print("Invalid choice. Please enter a valid number")
- else:
- print("Invalid choice. Please enter a valid number")
- if __name__ == "__main__":
- main()
- create_custom_hotkey()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement