Sign in to follow this  
Followers 0
stevwolf

Window not getting focus or at least not getting sent keyboard strokes

14 posts in this topic

Im running windows 7 64 bit. Using 3.3 version of software.

I'm trying to open a program that is on a usb key. Then automate the process of setting a few aspects of the program that I have to do every time I open it.

I can start the program, but when I try to sent Alt f to it after its open or anything to this program, the top window it doesnt seems to take any keyboard commands. I have tried, Alt keys, Tab key, Enter. Its just like the program is not in focus. And yet when the script stops if I just hit enter or alt f or what ever it does appear to have focus.

I have tried, WinWaitActive, WinActive, I have tried using class, tried putting title in the function, nothing seems to work.

I will provide my code. I should note is filled with ; 's as I have tried various options to test it out. At the end there is a msgbox that opens for debugging only. My thinking is that if the winwaitactive or winactive is found then it will proceed and not untill then, thus proving that its found the window. Indeed the msgbox does open (in my mind proving that the window is open and active) but still when I send keys to the the window it does not work.

sleep(100)

; start the program, it starts flawlessly

Run("G:\truecrypt.exe" )

sleep(500)

;WinWaitActive("TrueCrypt")

WinActivate("TrueCrypt")

;WinWaitActive("[Class:CustomDlg]", "", 5)

;WinActivate("[Class:CustomDlg]")

;winactive(class: CustomDlg "TrueCrypt")

sleep(500)

MsgBox(64, "USB", "TC Open Now.")

Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

does this example help, with sending keys and checking if windows are active. Remember you can press F1 with your cursor over functions to see them with the help file.

; Matches any substring in the title, letter case is forced to lower so not case sencitive
AutoItSetOption("WinTitleMatchMode", -2)
Run("notepad" )
WinWaitActive("notepad")
;woops
send("!{f4}"); closes the window
Edited by songersoft

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This code works fine for me. Note though, TrueCrypt does not have a main File menu, so ALT-F will do nothing.

Run("C:Program FilesTrueCryptTrueCrypt.exe")
WinWaitActive("TrueCrypt")
Send("!v")

edit: OK, so alt-f will bring up a dialog titled "Select a TrueCrypt Volume"

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try doing it this way. Make sure you don't have any Windows Explorer windows open to your truecrypt folder.

#region ---Au3Recorder generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
$Container = @ScriptDir & "TestVolume" ; Change to your file name
$Password = "YourPassword" ; Change to the password for the container
Run('J:TrueCryptTrueCrypt.exe')
_WinWaitActivate("TrueCrypt","&Create Volume")
ControlSend("TrueCrypt", "&Create Volume", "[CLASS:Button; INSTANCE:17]", "!F")
_WinWaitActivate("Select a TrueCrypt Volume", "Namespace Tree Control")
Sleep(100)
ControlSend("Select a TrueCrypt Volume", "Namespace Tree Control", "[CLASS:Edit; INSTANCE:1]", $Container & "{ENTER}")
_WinWaitActivate("TrueCrypt","&Create Volume")
ControlSend("TrueCrypt", "", "[CLASS:Button; INSTANCE:17]", "!M")
_WinWaitActivate("Enter password for", "")
ControlSend("Enter password for", "", "[CLASS:Edit; INSTANCE:1]", $Password & "{ENTER}")
#region --- Internal functions Au3Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au3Recorder End ---

#endregion --- Au3Recorder generated code End ---

I used the AU3recorder, but you can just use WinWait and WinWaitActive instead of using _WinWaitActivate that the recorder creates.

Edited by BrewManNH

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

Thanks, Well several people have reponded, and Im not going to be able to test it unill Im home.

But I do have a few questions, First Im very new at this so excuse my skirt from showing.

somdcmputerguy - you say there is no menu, but shouldnt alt f still work. It does when Im on my keyboard doing it manually, it selects the proper button, but even if alt does not work tab does not work either, even enter does not work, which I tried just to get some action of some kind to work. It all does not work for me.

BrewmanNH - Thanks for the info. I tried using a macro prgram. But where Im confused is that the functions start with _ (an underscore) But when I tried to run the macros I get invalid syntax or function doesnt exist something like that, at least when I run it. What am I missing, why do the functions start with a _ when I dont think thats right.

Thanks.

Share this post


Link to post
Share on other sites

The only function in the script I posted is _WinWaitActivate. If you used the script exactly as I posted it, it should work fine. Function names can start with an underscore, it's very common to use an underscore as the first character of a function name.


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

somdcmputerguy - you say there is no menu, but shouldnt alt f still work. It does when Im on my keyboard doing it manually, it selects the proper button, but even if alt does not work tab does not work either, even enter does not work, which I tried just to get some action of some kind to work. It all does not work for me.

Yes, alt-f does work. I edited my post just a few minutes before you made your post that I've quoted here. Does Send or ControlSend work for any other application on your computer? Try songersoft's example he posted. If that doesn't work either, maybe you have something running that is blocking the Send function. Also, make sure you're using the correct Send syntax.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Well sonersofts code does work. But still mine does not.

The other code that others had that specifically opened my program, does not work. What I mean by this is that it opens the TrueCrypt but the keys are not sent to the program. I have installed the autoit on XP and it seems to work, that is my code seems to open and send the keys to the program. So it is something about my computer and windows 7.

I have disabled the MS Virus (Security Esentials) program, or at least made it so it is not doing checking actively. IM not sure how to turn it off completely. There doesnt seem to be a disable mode like other Virus program.

I normally log in as a user on my win7, not administrator. So when I start truecrypt manuall or through AutoIt it asks for adminisrtator password, which I give and then it opens, but still it doesnt get the sent keys. I even tryed to run it as administrator, which then doesnt ask for admin password but I have to say yes to it. But still nothing.

Any further ideas what could be stopping the program from running or what test can be done.

Further to above. Is the a program that I can use to see what is causing the problem. Some sort of debug thing. I have looked at the various programs that came with autoit but becasue its all fresh to me its a little daunting seeing all the differnt programs and feature and sorting out what they do.

Regards

Share this post


Link to post
Share on other sites

I tested my code on Windows 7 x86 Enterprise and it worked on that version. Seeing as how you haven't really posted any of your own code, we have no way of knowing what you're doing that's not working. If Songersoft's version works and your's doesn't it has to be something in your script that is written wrong. Post your script and we might be able to help.


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

Ok well here is the code that works on my XP and not on my windows 7 Prof.

; Script Start - Add your code below here

sleep(100)

Run("J:truecrypt.exe" )

sleep(400)

WinActivate("TrueCrypt")

sleep(400)

send("!f")

sleep(400)

send("J:how-u")

sleep(500)

Send("{TAB 2}" )

sleep(500)

Send("{ENTER}")

sleep(700)

Send("U")

sleep(700)

Send("!m")

The truecrypt opens but no keys are sent to the window.

As I mentioned before. I run as user, so before truecrypt starts the os asks me for the administrator password, before it can install the Truecrypt. However even if I put a big pause before the alt -F just after opening the Truecrypt, it still does nothing. Can entering the password stop it from sending keys, I dont think so but still confused?

Regards

Share this post


Link to post
Share on other sites

Don't use the sleep function to pause your script, use WinWaitActive and WinWait to see if the windows are there. 400 milliseconds probably isn't nearly enough time for the window to appear before your script is starting to send keystrokes to it and the rest of the windows. You should probably try looking at the script I posted to see how I accomplished this and see if you can adapt it to your use.


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

I guess I was tring to make it as simple as possible so that any mistakes would be caught easily. Once it worked then fine tune it. Sleeps were easy and I did make them long at times during my testing eg 10000. But still nothing?

Share this post


Link to post
Share on other sites

I have been experimenting with variations of WinWaitActive, Sleep, Send, ControlSend, and ControlSetText. The results of these experimentations has led me to gratefulness that TrueCrypt accepts many command line arguments. Since I, and you, have not had any difficulties with the Run command (don't forget ShellExecute..), try some command line arguments to get done what you want, instead of some script automation. I'm not too surprised that TrueCrypt doesn't play well with automations.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

somdcomputerguy

Thanks for your idea. I think I have run into a brick wall on this.

The code appers to work, on xp but not on my 64 bit win7 professional. I'm going to investigate a comand line execute of what I want, as I think you have suggested. That will avoid the gui problems. I see that truecrypt does have some of these abilities. It may be a better and frankly more resiliant. I have to admit that it bugs me that i cant get it to work, but I have to let go and move on. There just has to be something on my computer that is preventing it from working. I just dont know what.

Thanks.

Share this post


Link to post
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
Sign in to follow this  
Followers 0