I hope Someone Can Commentoon My Code Errors

Get help with using AutoHotkey and its commands and hotkeys
BillW
Posts: 28
Joined: 01 Aug 2017, 15:24

I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 10:46

I'm new at this! I have written several little test scripts and have them working. Now I'm working on the little routine that I really need to use and I'm still very unclear on a lot of syntax issues and my script is not working. I'm hoping someone will be kind enough to point out my errors. Here is the current state of my routine:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force

^m::
Loop
{
	Sleep 500
	MsgBox Loop Cnt is "%A_Index%".
	if A_Index > 9 
	{
		ExitApp
	}
	WinGetTitle, Title, A
	MsgBox Active Window is "%Title%"
}
until Title := "C:\Users\BillWilson\Temp\Test1"

; Found it; Close it
WinKill "C:\Users\BillWilson\Temp\Test1"

return
User avatar
Gio
Posts: 1060
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 11:01

Hello BillW.

Welcome to the AutoHotkey community forums.

This line:

Code: Select all

until Title := "C:\Users\BillWilson\Temp\Test1"
Is using an expression assignment operator (:=), which does not serve as a comparisson operator.

Use the regular equals (=) operator whenever you wish to compare values. It is also a good idea to enclose your comparissons between parenthesis.

Code: Select all

until (Title = "C:\Users\BillWilson\Temp\Test1")
If something else is not to your design, please provide more in-depth feedback about how the routine should behave.

Best wishes.
BillW
Posts: 28
Joined: 01 Aug 2017, 15:24

Re: I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 15:12

Thanks for the correction Gio. The routine is still not doing all that I need done so let me explain what my objective is.

I have volunteered to maintain 2 laptop computers at my church. Since I don't live next door to the church I have been experimenting with using Team Viewer to remotely connect to each of those computers to see if updates are pending and to see if they are running OK. The problem is that when I disconnect Team Viewer from either of those computers it pops up a message box as it disconnects. The message box says something about my using the free version of Team Viewer. One of the computers is used to run a full-time display in the church-office lobby so I can't leave it with some message being displayed on top of the display that is intended for that message board. So, my objective is to initiate an AutoHotKey routine just before disconnecting Team Viewer and have that routine look for and close the pop up message and then close itself.

In it current state, the AutoHotKey routine is finding the message box (named "Test1" right now) but it is not closing it. I should point out that the window I'm trying to close in my testing at home right now is a File Explorer window. I have manually created a sub-folder named Test1 and I have assumed that WinKill is able to close it. If that is not possible then that may be my current problem!

Thanks,
Bill
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 17:00

The following should close the team viewer message box:

Code: Select all

settimer closeTeamNag

return

closeTeamNag:
	WinWaitActive, Sponsored session
	send, {enter}
return
BillW
Posts: 28
Joined: 01 Aug 2017, 15:24

Re: I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 18:51

WOW obeeb! That is certainly simple! Unfortunately, there is one case that I haven't mentioned that still needs to be accounted for: I have noticed while testing my use of Team Viewer at home that sometimes the popup message does not show up! I don't know why but I expect it is related to what activity I performed or didn't perform while connected. So, I intended my code to give up and exit if it did not find the popup message over a small period of time. Is there a simple change to your code that will account for this situation in case it comes up?

I really appreciate your suggestion.
Bill
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 18:58

Sure, what I wrote is something you can run and just keep it running and it will close this message box when it will appear. How do you want to use it?
BillW
Posts: 28
Joined: 01 Aug 2017, 15:24

Re: I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 19:35

I was planning on only running my routine when it was needed, as I close a remote connection in Team Viewer. I'm am generally not in favor of running something all the time just in case it might be needed. I realize your routine won't use much, if any, resources while it is running but the idea of leaving it running just does not appeal to me.

Thank for your help.
Bill
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 21:30

ok, then you can just wait for let's say 10 seconds and exit the script if there is no message

Code: Select all

closeTeamNag:
	WinWaitActive, Sponsored session, , 10
	if (!ErrorLevel)
		send, {enter}
	ExitApp
return
BillW
Posts: 28
Joined: 01 Aug 2017, 15:24

Re: I hope Someone Can Commentoon My Code Errors

28 Aug 2017, 22:18

Thanks obeeb. That should keep me satisfied and the whole thing is still very nice and short.

Bill
BillW
Posts: 28
Joined: 01 Aug 2017, 15:24

Re: I hope Someone Can Commentoon My Code Errors

29 Aug 2017, 10:43

When I use the SciTE4AutoHotkey script editor to create a new script it automatically adds the following lines at the beginning of the script:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Should those lines be included in the file that contains the script suggested in the earlier posts in this thread? I'm not clear when those code lines are important in a script.

Thanks,
Bill
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: I hope Someone Can Commentoon My Code Errors

29 Aug 2017, 14:51

Yes, they are just recommended defaults, leave them and put the actual script below.
BillW
Posts: 28
Joined: 01 Aug 2017, 15:24

Re: I hope Someone Can Commentoon My Code Errors

05 Sep 2017, 15:46

obeeb wrote:The following should close the team viewer message box:

Code: Select all

settimer closeTeamNag

return

closeTeamNag:
	WinWaitActive, Sponsored session
	send, {enter} 
return
I'm back on this subject after some interruptions! The code above is your original suggestion which is supposed to run all the time. I had tried to use your latest version of this script that does not run all the time and it did not seem to do anything so I have switched to the one shown above. It also does not close the window with the "Sponsored session" title. I have another little scrip that simply displays the title of the active window and it says that the window I want to close does have that title.

1. Is there some way to see that a script is in fact running, i.g. maybe in the Task Manager?

2. Am I correct in assuming that clicking on the Run button in the Scrip Editor is a valid way to activate a script?

3. Any other suggestions at this point?

Thanks,
Bill

Return to “Ask For Help”

Who is online

Users browsing this forum: ahmad1829, Bing [Bot], boiler, drewjbx1, evilmanimani, Google [Bot], mikeyww, TAC109, Xtra and 51 guests