Jump to content
Sign in to follow this  
sreekanthrcs62

Problem in Hiding and Sending Keystrokes to Application Execution

Recommended Posts

sreekanthrcs62

#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

Share this post


Link to post
Share on other sites
FireFox

Hi,
Welcome to the autoit forum :)

First of all, can you edit your post and use >autoit code tags to post your code because here we will have to remove all the line numbers :(

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
reb

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

Share this post


Link to post
Share on other sites
FireFox

My bad, it was just a remark I did not test it.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FireFox

The ControlSend function appears not to be working when the window is not active, in this case of the edit control.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FireFox

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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
AdamUL

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
  • Like 1

Share this post


Link to post
Share on other sites
FireFox

Nice shot ;)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
AdamUL

Thanks,

As soon as I seen this thread, and your replay, I figured that it was a control focus issue.  

 

Adam

Share this post


Link to post
Share on other sites
sreekanthrcs62

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.

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
sreekanthrcs62

The softwares are TextAnalysisTool and SequenceDiagramEditor. 

Share this post


Link to post
Share on other sites
Bert

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.