import keyboard
import pyautogui
import time
def press_page_up():
“””
1. Simulates pressing the page-up button on the keyboard.
“””
keyboard.press_and_release(‘page up’)
def move_cursor_to_position(position):
“””
2. Moves the cursor to the specified position on the screen.
“””
pyautogui.moveTo(position[0], position[1])
def click_current_position():
“””
3. Simulates a left mouse click at the current cursor position.
“””
pyautogui.click()
def press_tab_key():
“””
4. Simulates pressing the Tab key once on the keyboard.
“””
keyboard.press_and_release(‘tab’)
def press_ctrl_enter_keys():
“””
5. Simulates pressing Ctrl+Enter keys on the keyboard.
“””
keyboard.press_and_release(‘ctrl+enter’)
def click_at_coordinates(x, y):
“””
6. Simulates a left mouse click at the specified coordinates (x, y) on the screen.
“””
pyautogui.click(x, y)
def press_ctrl_a():
“””
7. Simulates pressing Ctrl+A to select all.
“””
keyboard.press_and_release(‘ctrl+a’)
def press_ctrl_c():
“””
8. Simulates pressing Ctrl+C to copy.
“””
keyboard.press_and_release(‘ctrl+c’)
def press_ctrl_f():
“””
9. Simulates pressing Ctrl+F to open the find dialog.
“””
keyboard.press_and_release(‘ctrl+f’)
def type_find_text(text):
“””
10. Types the specified text in the find dialog.
“””
pyautogui.typewrite(text)
def click_tab_key_three_times():
“””
11. Simulates clicking the Tab key three times on the keyboard.
“””
for _ in range(3):
keyboard.press_and_release(‘tab’)
# Function to stop the script when ‘s’ key is pressed
def stop_script(event):
“””
Stops the script when the ‘s’ key is pressed.
“””
if event.name == ‘s’:
print(“Script stopped.”)
exit()
# Listen for the ‘s’ key press to stop the script
keyboard.on_press(stop_script)
# Execute the rest of the script steps
# Function to execute steps from Step 5 to the end of the script
def execute_steps():
# Execute Step 5: Simulate pressing Ctrl+Enter keys
press_ctrl_enter_keys()
# Wait for 5 seconds before clicking on specific coordinates (312, 15)
time.sleep(5)
# Execute Step 6: Click on specific coordinates (312, 15)
click_at_coordinates(312, 15)
# Execute Step 7: Simulate pressing Ctrl+A to select all
press_ctrl_a()
# Execute Step 8: Simulate pressing Ctrl+C to copy
press_ctrl_c()
# Wait for 2 seconds
time.sleep(2)
# Click on specific coordinates (479, 13)
click_at_coordinates(479, 13)
# Wait for 2 seconds
time.sleep(2)
# Step 12. Type the words “Assignment Question”
pyautogui.typewrite(“Assignment Question”)
# Step 13. Simulate pressing the Tab key once
press_tab_key()
# Step 14. Simulate pressing Ctrl+V to paste
keyboard.press_and_release(‘ctrl+v’)
# Wait for 2 seconds
time.sleep(2)
# Step 15. Simulate pressing Ctrl+F to open the find dialog
press_ctrl_f()
# Step 16. Type the words “move to trash” in the find dialog
type_find_text(“move to trash”)
# Step 17. Click on specific coordinates (1282, 452)
click_at_coordinates(1282, 452)
click_at_coordinates(1283, 471) # Second click
# Step 18. Wait for 5 seconds
time.sleep(5)
# Step 19. Click on specific coordinates (345, 96)
click_at_coordinates(345, 96)
# Step 20. Wait for 2 seconds
time.sleep(2)
# Step 21. Click on specific coordinates (314, 15)
click_at_coordinates(314, 15)
# Step 22. Wait for 2 seconds
time.sleep(2)
# Step 23. Simulate pressing Ctrl+W to close the window
keyboard.press_and_release(‘ctrl+w’)
# Step 24. Click on specific coordinates (126, 14)
click_at_coordinates(126, 14)
# Step 25. Wait for 1 second
time.sleep(1)
# Step 26. Click the Tab key three times
click_tab_key_three_times()
# Execute steps for a total of 9 times
for _ in range(9):
execute_steps()