Using the EleIf command

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
stevesax
Posts: 22
Joined: 12 Jun 2017, 15:25

Using the EleIf command

23 Jun 2017, 11:38

Hi, I'm new to AHK, but have experience in scripting with a screenreader called Jaws. I'm visually impaired and I'm now using AHK to access some inaccessible apps. I'm currently going crazy with the following code, as I get an error "else with no matching if". Here's the code and comments on what it's supposed to do:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Recommended for catching common errors.
#UseHook
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode, Mouse, Window
oVoice:=ComObjCreate("SAPI.SpVoice")
Global XPos, YPos, Color

; Toggle Preferences

^,::
If (IsKKPreferences() = 1) ;this function returns 1 if this window is open
; Objective, to get AHK to close the preferences
{
GetReferencePosition() ; this function places the mouse in a consistent place on the target window, so that mouse movements are consistent in programs in which it is used
Sleep, 100
MouseMove, 130, 298, , R
Click
oVoice.Speak("PreferencesClosed:") ; this uses SAPI to give feedback to the visually impaired user
}
ElseIf (IsKK() = 1) ; if the main KK window is open and it's not the prefferences
{
Send, ^,; send the default keystroke in this app in order to open the preferences
oVoice.Speak("PreferencesOpen:") ; again spoken feedback
}
Else
{
MsgBox "not in any KK window" ; if it's not the KK or KK preferences window, do the default/ normal key action
}


I'm pretty sure it's to do with my implamentation of {}'s, so trying to get a grip of it :)...any help would be greatly appreciated. Objective is to only have the key/voice active when this program is active and in focus, but to do the default action otherwise.
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Using the EleIf command

23 Jun 2017, 11:40

put a space between the else and the if

Code: Select all

Else If (IsKK() = 1) ; if the main KK window is open and it's not the prefferences
stevesax
Posts: 22
Joined: 12 Jun 2017, 15:25

Re: Using the EleIf command

23 Jun 2017, 15:16

Hi Nightwolf85, that's done the trick, thanks so much...it's the little things that trip us up :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: macromint and 253 guests