microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.88k stars 8.34k forks source link

Mouse cannot select text with pyautogui #16268

Open ebundy opened 1 year ago

ebundy commented 1 year ago

Windows Terminal version

1.17.11461.0

Windows build number

10.0.19045.3570

Other Software

python 3.10, pyautogui 0.9.5 (The exact versions doesn't matter actually)

Steps to reproduce

Install the pyautogui library (The version doesn't matter). Execute the following code and you have 3 seconds to switch to the terminal and position the cursor on any text.

from time import sleep

import pyautogui
from pyautogui import Point

sleep(3)
pyautogui.click()
pyautogui.mouseDown(button='left')
for i in range(50):
    position: Point = pyautogui.position()
    pyautogui.moveTo(position.x + 4, position.y)
pyautogui.mouseUp(button='left')

Expected Behavior

The text where the cursor is positioned starts to be selected towards the right. FYI : I tested that code on other terminals like classic windows terminal, Git Bash and WSL2 and the problem doesn't occur.

Actual Behavior

The cursor is positioned at the right place and progress to the right as expected but no selection happens. ezgif-1-639c7a0728

zadjii-msft commented 1 year ago

Here's possibly a dumb question - does it work if the Terminal isn't running as admin[^1]/? There's typically quite a few protections in place (by Windows itself) that prevent unelevated apps from sending input to elevated ones

[^1]: Or, the inverse: is pycharm (or whatever's running your pyautogui script) running as admin?

ebundy commented 1 year ago

I checked and none of the two applications (Terminal and Pycharm) are running in admin. I tried to run in admin both and the behavior is the same. As stated previously, I notice the expected behavior with the classic Windows terminal, Git Bash terminal and WSL2 terminal and that is true in the exact same execution context (no admin running), so I assume that the problem is specific to the (modern) Microsoft Terminal implementation. If some additional information could be helpful, please tell me what, I would like my best to provide it. Note : I also tried with the most recent preview build (Microsoft.WindowsTerminalPreview_1.19.2831) but unfortunately the issue persists.

zadjii-msft commented 1 year ago

image That little shield icon means either:

ebundy commented 1 year ago

EDIT : I managed to run the two applications in non-administrator and the problem persists. ezgif-2-e8f99b381c

ORIGINAL: Good point. I checked the state of the process and it turns out that the process is running as administrator (elevated column in process explorer). Wichis surprising because I didn't execute it as an administrator. I also checked my UAC, indeed they were disabled entirely. I re-enabled them (intermediary level) and I restarted my computer. Now Windows Terminal asks me a permission because "the application can do some modification on my computer." If I validate the opening, the problem remains. The application is still executed as an administrator. If I don't the application is not opened. I tried the hints provided by users in this issue (https://github.com/microsoft/terminal/issues/13197) but it seems to be not working in my case like for some others. I also tried to run the program as a regular user with this syntax but it seems to be not acceptable for the terminal : wt.exe /runas. I have a Windows error saying that /runas is a not valid argument for wt.exe.

Did you have other ideas on how I may fix it?

yg-i commented 5 months ago

I maybe experiencing the same issue as @ebundy

@ebundy:

For me the answer is 'no' to all the above.