K
K
korvin22018-10-20 20:11:07
Python
korvin2, 2018-10-20 20:11:07

How to get selected text from windows application without using clipboard?

I have a Windows application that cannot copy text. But I need to somehow copy (or just output) the selected text, I tried this

import pyautogui as pya
import pyperclip
import time
import keyboard


def copy_clipboard():
    pya.hotkey('ctrl', 'c')
    time.sleep(0.1)
    return pyperclip.paste()

while True:
    try:
            if keyboard.is_pressed('q'):
                print('You Pressed A Key!')
                pya.doubleClick(pya.position())
                var = copy_clipboard()
                print(var)
                break
            else:
                pass
    except:
            break

but from this application the text is simply not copied. It is very necessary to solve this problem, if you have ideas, but no code - it's okay :) Do not offer text recognition from a screenshot of the screen, I already tried it - it is recognized with errors, but the selected text is needed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2018-10-20
@tsklab

Find the window Handler, then the control. And EM_GETSELTEXT .
Program:
5bcb6ba48c9a3816313051.png

E
Ezhyg, 2018-10-20
@Ezhyg

Look for programs that work with windows, there were dozens of them before, now they are not so popular, but they still work, even very old ones (I have a special selection of such programs).
Search by keywords "Window Scanner", "Window Scanner", "Window Spy", etc. Here the difficulty will be only in choosing between different ones and wasting time trying a dozen utilities.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question