Jump to content

Problem in Hiding and Sending Keystrokes to Application Execution


Recommended Posts

#include <MsgBoxConstants.au3>
Example()

Func Example()
Run("notepad.exe a.txt")
WinWait("a.txt - Notepad")
WinSetState("a.txt - Notepad","", @SW_HIDE)
Sleep(1000)
Local $value = ControlSend("a.txt - Notepad", "", "Edit1", "^a")
Sleep(2000)
MsgBox($MB_SYSTEMMODAL, "AutoIt Example", $value)
Sleep(1000)
Local $value2 = ControlSend("a.txt - Notepad", "", "Edit1", "^c")
Sleep(2000)
MsgBox($MB_SYSTEMMODAL, "AutoIt Example", $value2)
Sleep(1000)
Run("notepad.exe")
WinWait("Untitled - Notepad")
WinSetState("Untitled - Notepad","", @SW_HIDE)
Sleep(2000)
Local $value3 = ControlSend("Untitled - Notepad", "", "Edit1", "^v")
Sleep(1000)
MsgBox($MB_SYSTEMMODAL, "AutoIt Example", $value3)
Sleep(1000)
WinSetState("Untitled - Notepad","", @SW_SHOW)
EndFunc

 

 

I tried to execute the above code with having"@SW_HIDE" values in the Run command.

Applications are hidden but the controlSend commands are not working fine. 

After removing the "@SW_HIDE" values in the Run command, controlsend command works, but the application window is not hidden.

I tried checking the flags returned from controlsend command. Flag Values are showing 1, I assume it is fine.

Please Could you help me to fix this problem. Thanks in advance.

Edited by sreekanthrcs62
Link to comment
Share on other sites

AutoIt  Code Tags are much better to use and read.

 

because here we will have to remove all the line numbers :(

 

Out of curiosity I tried to copy the code in the first post

and the numbers did not copy. Pasted into SciTe correctly.

Just my observation  Win7 64  firefox 27.0.1

REB

Edited by reb

MEASURE TWICE - CUT ONCE

Link to comment
Share on other sites

After a few trys using some WinAPI function to reproduce the ControlSend command, the window must be active to send the keystrokes (here I'm using _WinAPI_SetForegroundWindow).

#include <WinAPISys.au3>

Example()

Func Example()
    Run("notepad.exe a.txt", "", @SW_HIDE)

    Local $hNotepad = WinWait("[TITLE:a.txt; CLASS:Notepad]")

    _WinAPI_SetForegroundWindow($hNotepad)

    ControlSend($hNotepad, "", "[CLASS:Edit; INSTANCE:1]", "^a")

    ;the following lines does not change anything for your information
;~  ControlSend($hNotepad, "", "[CLASS:Edit; INSTANCE:1]", "^c")

;~  ControlSend($hNotepad, "", "[CLASS:Edit; INSTANCE:1]", "^v")

    WinSetState($hNotepad, "", @SW_SHOW)
EndFunc   ;==>Example

_

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

From the Help file for ControlSend.

The control might first need to be given focus with the ControlFocus() command, specially when referencing an controlID created by the script itself.

 
This also applies to GUIs not created by the script itself.  As a rule of thumb, I always use ControlFocus before "Control" commands.  This should work for you.

#include <MsgBoxConstants.au3>
Example()

Func Example()
    Run("notepad.exe a.txt","", @SW_HIDE)
    WinWait("a.txt - Notepad")
    WinSetState("a.txt - Notepad","", @SW_HIDE)
    Sleep(1000)
    ControlFocus("a.txt - Notepad", "", "Edit1")
    Local $value = ControlSend("a.txt - Notepad", "", "Edit1", "^a")
    Sleep(2000)
    MsgBox($MB_SYSTEMMODAL, "AutoIt Example", $value)
    Sleep(1000)
    ControlFocus("a.txt - Notepad", "", "Edit1")
    Local $value2 = ControlSend("a.txt - Notepad", "", "Edit1", "^c")
    Sleep(2000)
    MsgBox($MB_SYSTEMMODAL, "AutoIt Example", $value2)
    Sleep(1000)
    Run("notepad.exe","", @SW_HIDE)
    WinWait("Untitled - Notepad")
    WinSetState("Untitled - Notepad","", @SW_HIDE)
    Sleep(2000)
    ControlFocus("Untitled - Notepad", "", "Edit1")
    Local $value3 = ControlSend("Untitled - Notepad", "", "Edit1", "^v")
    Sleep(1000)
    MsgBox($MB_SYSTEMMODAL, "AutoIt Example", $value3)
    Sleep(1000)
    WinSetState("Untitled - Notepad","", @SW_SHOW)
    WinSetState("a.txt - Notepad","", @SW_SHOW)
EndFunc

Adam

Edited by AdamUL
Link to comment
Share on other sites

Methods you mentioned are working for the installed software e.g Notepad in the machine.

For software(.exe) file which can run without installation in the machine this methods of using @SW_HIDE doesn't work.

Below mentioned code doesn't hide the window for some *****.exe. 

Run("****.exe a.txt","", @SW_HIDE)     
WinWait("a.txt - Notepad")    
WinSetState("a.txt - Notepad","", @SW_HIDE)

Could you Please suggest some alternative.

Thanks in advance.

Link to comment
Share on other sites

Perhaps if you explained what software you're trying to run hidden that would help us help you. Just saying some software doesn't run hidden isn't much to go on.

BTW, some software will resist your attempts to run it hidden, it all depends on what the program does or how it was written.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

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...