I found the answer!
It wasn't selecting text for me as long as num lock was enabled.

Make sure num lock is disabled when using pyautogui

Answer from Kerwin Sneijders on Stack Overflow
🌐
PyAutoGUI
pyautogui.readthedocs.io › en › latest › quickstart.html
Cheat Sheet — PyAutoGUI documentation - Read the Docs
>>> pyautogui.typewrite('Hello world!\n', interval=secs_between_keys) # useful for entering text, newline is Enter
Discussions

Can't select text
Hello, I really hope this is just me, but I can't select text in windows 7, python 3.4 using v0.9.30: import pyautogui as p import time as t t.sleep(3) p.keyDown('shift') p.press('l... More on github.com
🌐 github.com
7
July 27, 2015
Cannot click-and-drag to select text
I would like to be able to select text from a window to copy it. In the particular application, click-and-drag is the only way to select (unlike a word processor where I could possibly 'shift'+'up' or 'down'). To recreate: I have the following script in an IDE: import pyautogui pyautogui.m... More on github.com
🌐 github.com
1
December 16, 2020
python 3.x - Move to searched text on active screen with pyautogui - Stack Overflow
I am trying to make a program that searches for a text on a web-page, then places the mouse cursor on the highlighted text after it has been found. Is this possible using pyautogui? If so, how. If ... More on stackoverflow.com
🌐 stackoverflow.com
python - Copy highlighted text to clipboard, then use the clipboard to append it to a list - Stack Overflow
I'm trying to automate some actions in a browser or a word processor with pyautogui module for Python 3 (Windows 10). There is a highlighted text in a browser. text the following script should p... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/learnpython › pyautogui - problems with selecting text
r/learnpython on Reddit: pyautogui - Problems with selecting text
November 29, 2017 -

I've tried with .hotkey('shift','end') and using keyDown + press combinations to do the same.

It does the 'end' and put the cursor at the end of the sentence but, does not hold the shift. Hence, no text is selected.

I've tried shift otherwise, like .hotkey('shift', 'p') and that does give me a capital p.

🌐
GitHub
github.com › asweigart › pyautogui › issues › 40
Can't select text · Issue #40 · asweigart/pyautogui
July 27, 2015 - Hello, I really hope this is just me, but I can't select text in windows 7, python 3.4 using v0.9.30: import pyautogui as p import time as t t.sleep(3) p.keyDown('shift') p.press('l...
Author   MrSimonC
🌐
GitHub
github.com › asweigart › pyautogui › issues › 506
Cannot click-and-drag to select text · Issue #506 · asweigart/pyautogui
December 16, 2020 - In the particular application, click-and-drag is the only way to select (unlike a word processor where I could possibly 'shift'+'up' or 'down'). To recreate: I have the following script in an IDE: import pyautogui pyautogui.mouseDown() ...
Author   dplefevre
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 2e › chapter20
20 controlling the keyboard and mouse with gui automation
You can use PyAutoGUI to obtain the window for a text editor such as Mu or Notepad, bring it to the front of the screen by clicking on it, click inside the text field, and then send the CTRL-A or -A hotkey to “select all” and CTRL-C or -C hotkey to “copy to clipboard.” Your Python script ...
Find elsewhere
🌐
PyAutoGUI
pyautogui.readthedocs.io › en › latest › keyboard.html
Keyboard Control Functions — PyAutoGUI documentation
>>> pyautogui.press('enter') # press the Enter key >>> pyautogui.press('f1') # press the F1 key >>> pyautogui.press('left') # press the left arrow key
🌐
CodePal
codepal.ai › code-generator › query › CCACYmPG › python-find-and-click-text
Python Find and Click Text with pyautogui - CodePal
The function takes two parameters: target_text and click_text, which represent the texts to be searched for and clicked on the screen, respectively. To accomplish this task, the function utilizes the locateOnScreen function from the pyautogui library to search for the target and click texts on the screen...
🌐
GitHub
github.com › asweigart › pyautogui › issues › 521
Screenshot functions and "find text on screen in a dialog box" · Issue #521 · asweigart/pyautogui
January 7, 2021 - Render the text with the default Windows GUI font (Segoe UI?) to a search.png file, and then use pyautogui.locateOnScreen('search.png') ?
Author   josephernest
🌐
Stack Overflow
stackoverflow.com › questions › 73562367 › pyautogui-copying-selected-text
pyautogui - copying selected text - Stack Overflow
And manually alt-tab from the code editor to the browser window with selected text, it works fine. Trying to automate the alt-tab doesn't seem to work b/c the alt-tab window stays on screen instead of briefly flashing the way it does when manually executed. pyautogui.hotkey("alt", "tab") # alt-tab time.sleep(2) pyautogui.hotkey("ctrl", "c") #copy
🌐
Topcoder
topcoder.com › thrive › articles › python-for-gui-automation-pyautogui
PYTHON FOR GUI AUTOMATION – PYAUTOGUI
December 15, 2020 - 1 2 3 4 5 import pyautogui pyautogui.hotkey('ctrl', 'c') # ctrl - c to copy pyautogui.hotkey('ctrl', 'v') # ctrl - v to paste pyautogui.hotkey('ctrl', 'a') # ctrl - a to select all · Individual keys can also be pressed and released.
🌐
AskPython
askpython.com › home › auto-type text using python pyautogui
Auto-Type Text Using Python Pyautogui - AskPython
January 30, 2022 - To get some time, for the user ... ... To open the text file of ours (typing-data.txt) we use the open() method of pyautogui library and open the file in Read format....
🌐
GitHub
github.com › microsoft › terminal › issues › 16268
Mouse cannot select text with pyautogui · Issue #16268 · microsoft/terminal
November 6, 2023 - from time import sleep import pyautogui ... + 4, position.y) pyautogui.mouseUp(button='left') The text where the cursor is positioned starts to be selected towards the right....
Author   ebundy
🌐
Orrvillecma
orrvillecma.org › eso-skyreach › pyautogui-select-text.html
Pyautogui select text
A Python Tkinter widget that is used to display a list of options for the user to select. arabic text recognition from pdf using python arcpy find which fields use domain arcpy select arcpy select visible raster are all parallelograms trapeziums are all squares trapeziums Are angles of a parallelogram equal are tuples in python mutable area of a circle python area of an equilateral triangle in python area of the sub submatrix pyautogui is a modle that can do many different dynamic things including sending virtual keypresses and mouse clicks to Windows.
🌐
PyTutorial
pytutorial.com › pyautogui-hotkey-master-keyboard-shortcuts-in-python
PyTutorial | PyAutoGUI hotkey(): Master Keyboard Shortcuts in Python
December 16, 2024 - import pyautogui import time def text_editor_automation(): # Select all text (Ctrl+A) pyautogui.hotkey('ctrl', 'a') time.sleep(0.5) # Copy text (Ctrl+C) pyautogui.hotkey('ctrl', 'c') time.sleep(0.5) # Create new document (Ctrl+N) pyautogui.hotkey('ctrl', 'n') time.sleep(0.5) # Paste text (Ctrl+V) pyautogui.hotkey('ctrl', 'v') time.sleep(0.5) # Save document (Ctrl+S) pyautogui.hotkey('ctrl', 's') # Run the automation text_editor_automation()
🌐
Reddit
reddit.com › r/learnpython › how to copy selected text to clipboard?
r/learnpython on Reddit: How to copy selected text to clipboard?
June 17, 2018 -

How can I select text and copy it to the clipboard?

The selection part actually works. Either with "ctrl+a" or a triple left mouseclick. But I can't "ctrl+c" it into the clipboard.

I tried it with pyautogui like a normal user would, but it doesn't work.

pyautogui.keyDown('ctrl')

pyautogui.keyDown('c')

pyautogui.keyUp('c')

pyautogui.keyUp('ctrl')

Pyperclip works to read out the content of the clipboard, but it seems like it can only copy strings to the clipbard, that need to be added manually like this:

Pyperclip.copy('test')

But I need to copy my text selection to the clipboard.

edit: if you know any other way to store selected text in a variable, that would be alright too