Jump to content

Cannot select text in the Windows Console Host (solved: Console running with elevated privilege)


Go to solution Solved by Nine,

Recommended Posts

Hi,

I cannot select the text in the Windows Console Host using this script

Opt("WinTitleMatchMode", 2)
#RequireAdmin                           ; <= this solved the problem
WinActivate ("Command")
Sleep(1000)
;MouseClick ("left", 800, 400)
Sleep(1000)
Send ("^a") 
Sleep(1000)
Send ("^c")
$text = ClipGet ()
MsgBox (0, "Clipboard", $text)

- CTRL-A using my keyboard DOES work

- CTRL-A using AutoitScript does NOT work

 

 

Edited by antai
Link to comment
Share on other sites

Hey,

First : you should do some error checking, eg read the help files and check after each step if everything is ok, for instance :

func assert($check, $msg, $line=@SCRIPTLINENUMBER)
    if (not $check) then
        MsgBox(0x10,'ERROR','Assert failed at line ' & $line & @CRLF & $msg)
        Exit
    endif
endfunc

local $res = WinActivate("Excavator")
; from the doc : WinActivate success return the value 0
assert($res = 0, 'WinActivate failed')

Then proceed step by step.

A guess why it doesnt work : you cannot simply use the window title, you maybe need to use the window handle (idk maybe).

A tool to help you with the windows title/class/etc : AU3Info.

As mentionned many time here: sending keystroke is usually a bad idea, however for the specific case of consoles it is not that simple to retrieve text buffer (it is doable but a bit tedious by working around the windows console api), so i guess it is a more "simple" solution to proceed as you do :)

Edited by 636C65616E
Link to comment
Share on other sites

9 hours ago, 636C65616E said:

sending keystroke is usually a bad idea, however for the specific case of consoles it is not that simple to retrieve text buffer (it is doable but a bit tedious by working around the windows console api), so i guess it is a more "simple" solution to proceed as you do :)

That error checking helped with the WinActivate() function, thanx. The Send() function however returns nothing.

The confusing point is that "all things equal" the Console

  • - does not react to keystrokes sent by the script but does
  • - does react to keystrokes sent byt the keyboard.

I.e. even when activated by hand and clicking inside the Window at the exact same moment the script does not work while physical keyboard does work.

 

// that brought me to just doing a test with a virtual keyboard and it works as well.

So a solution is to invoke virtual keyboard and send mouse clicks to the virtual keyboard. Kinda cumbersome and there's definitely something different how the script sends the kyes compared to the Windows built in virtual keyboard (that should be the same on the program level).

Link to comment
Share on other sites

  • Solution

You cannot send keys to a higher elevation program than the script is...You can find out if it is elevated with this :

 

If it is, then you need to use #RequireAdmin

Edited by Nine
Link to comment
Share on other sites

  • antai changed the title to Cannot select text in the Windows Console Host (solved: Console running with elevated privilege)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...