asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.47k stars 1.27k forks source link

why can't use the keyboard commands in Abbyy Finereader ? #792

Open me-suzy opened 1 year ago

me-suzy commented 1 year ago

I made a code that automatically opens one pdf file at a time with the help of the FineReader.exe program

yes, the file opens, but the key combination does not work in the code (although it works perfectly from the keyboard). is there something wrong with my code?

this is the key combination i want to use:

  1. "Ctr+Shift+S" (open File from the FineaReader menu)
  2. "Alt+T" (tab the transition to the combo in which the file extensions)
  3. "T" (Choose to save in Text format)
  4. "Enter" (Save actually)

This is my Python code:

import os
import subprocess
import time
import pyautogui

# Directorul cu fisierele PDF
pdf_dir = r'g:\1\2'

# Calea catre executabilul ABBYY FineReader
abbyy_path = r'"c:\Program Files (x86)\ABBYY FineReader 15\FineReader.exe"'

# Obtine o lista cu toate fisierele PDF din director
pdf_files = [f for f in os.listdir(pdf_dir) if f.endswith('.pdf')]
pdf_files.sort()  # Sorteaza lista de fisiere

# Deschide fiecare fisier PDF cu ABBYY FineReader
for pdf_file in pdf_files:
    pdf_path = os.path.join(pdf_dir, pdf_file)
    # Adauga ghilimele in jurul caii fisierului
    subprocess.run(abbyy_path + ' "' + pdf_path + '"', shell=True)

    # Asteapta ca ABBYY sa proceseze fisierul
    time.sleep(10)

    # 1. Trimite combinația de taste 'Ctrl+Shift+S' pentru a deschide meniul 'Save As'
    pyautogui.hotkey('ctrl', 'shift', 's')
    time.sleep(1)

    # 2. Trimite tasta Alt și tasta 't' pentru a accesa meniul de tipuri de fișiere
    pyautogui.hotkey('alt', 't')
    time.sleep(1)

    # 3. Trimite tasta 't' pentru a selecta 'Txt document'
    pyautogui.press('t')
    time.sleep(1)

    # 4. Trimite tasta Enter pentru a confirma
    pyautogui.press('enter')
    time.sleep(1)

    # Așteaptă un moment pentru a te asigura că fișierul a fost salvat
    time.sleep(5)

    # Închide ABBYY înainte de a continua cu următorul fișier
    pyautogui.hotkey('alt', 'f4')
    time.sleep(1)
EsJoseVi commented 1 year ago

I don't see any issue in your code, You could try to change the keyboard language or layout in your machine.