Sign in to follow this  
Followers 0
kjpolker

Alt+Tab function

13 posts in this topic

I have a simple request as I have not touched Autoit in several months (about a year) and I was asked to try and come up with a program for a buddy.

As part of the script I need to set a hot key to execute an alt+tab. I know I can use WinActivate but I prefer not to work with window titles. I am sure there is an easier was I may be overlooking. I couldn't find anything in the help file mainly because I am not sure a fancy name for switching between windows.

Please let me know what I need to achieve this!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Hmm. Touche! Will do :)

I assume I need to have some sort of a while loop so the program doesn't just run through and close. What should I have the while loop doing though?

Currently this is what I have

Local $Key

HotKeySet($Key, "Toggle") 

$Key = IniRead(@ScriptDir & "Config.ini", "KEY", "Key", "")

Func Toggle()
    Send("!{TAB}")
    EndFunc
Edited by kjpolker

Share this post


Link to post
Share on other sites

Ya I guess it has been quite a while.. Read the Example, HotKeySet.


- 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

Add a

While 1
Sleep(40)
Wend
to the bottom

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

Okay all good on that. Now I ran into another problem, I have an IniRead in my script, I want it to MsgBox if there is a blank in the Ini file, but continue on if not.

Example:

$Key = IniRead( @ScriptDir & "\Config.ini", "KEY", "Key", "")

If $Key = "" Then MsgBox(0, "Message", "Wait! No key has been set in Config.ini")
    ShellExecute( @ScriptDir & "\Config.ini")
    Exit

I assume that by using "" in the IfElse statement it reads the blank as being any key, so even if I put a key into the ini file this message still pops up. Isn't there a way to indicate a space? Or would that not work either?

Share this post


Link to post
Share on other sites

Okay all good on that. Now I ran into another problem, I have an IniRead in my script, I want it to MsgBox if there is a blank in the Ini file, but continue on if not.

Example:

$Key = IniRead( @ScriptDir & "\Config.ini", "KEY", "Key", "")

If $Key = "" Then MsgBox(0, "Message", "Wait! No key has been set in Config.ini")
    ShellExecute( @ScriptDir & "\Config.ini")
    Exit

I assume that by using "" in the IfElse statement it reads the blank as being any key, so even if I put a key into the ini file this message still pops up. Isn't there a way to indicate a space? Or would that not work either?

Look at your IF ... its a one line IF so only that line is conditional and the rest will always be executed.

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

So I use a If...Then...ElseIf...Then?

If $Key = "" Then
    MsgBox(0, "Message", "Wait! No key has been set in Config.ini")
    ShellExecute( @ScriptDir & "\Config.ini")
    Exit
Else
    Func Toggle()
    EndIf
EndIf

Gives me the error

"If" statement has no matching "EndIf" statement!

But I do have an EndIf... :) Edited by kjpolker

Share this post


Link to post
Share on other sites

Maybe this'll work - change the default in IniRead to "NoKey" or something like that. Then check if $key equals whatever you set the default to be.


- 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

@Jos - Oops, I didn't catch the one line If..

@ kjpolker - If you want to execute the Toggle() function, just call it like this "Toggle()", not "Func Toggle". That's where the 'No Matching' error is coming from.


- 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

So I use a If...Then...ElseIf...Then?

If $Key = "" Then
    MsgBox(0, "Message", "Wait! No key has been set in Config.ini")
    ShellExecute( @ScriptDir & "\Config.ini")
    Exit
Else
    Func Toggle()
    EndIf
EndIf

Gives me the error

But I do have an EndIf... :)

You have a FUNC statement in there which you do not want and an EndIf.

Please be a little patient and do some checking before posting each and every time you have a little mistake or setback.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Well I wanted to leave it blank to make it fail proof and screwing up the script. I got it now though, it was the Func that screwed it up so thank you! I ended up with

Global $Key 

$Key = IniRead( @ScriptDir & "\Config.ini", "KEY", "Key", "`")

HotKeySet($Key, "Toggle")

If $Key = "" Then
    MsgBox(0, "Message", "Wait! No key has been set in Config.ini")
    ShellExecute( @ScriptDir & "\Config.ini")
    Exit
Else
    Toggle()
EndIf

While 1
    ToolTip("Program is running")
    Sleep(100)
WEnd

Func Toggle()
    Send("!{TAB}")
    EndFunc

If you were curious.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Fixed the problems and fixed the annoying tooltip

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
Global $Key

Opt("WinTitleMatchMode",2)

$Key = IniRead(@ScriptDir & "\Config.ini", "KEY", "Key", "Blank")

If $Key = "Blank" Then
    IniWrite(@ScriptDir & "\Config.ini", "KEY", "Key", "Blank")
    ;The two lines below and the first wwhile loop could be replaced with an inputbox.
    MsgBox(0, "Message", "Wait! No key has been set in Config.ini")
    ShellExecute(@ScriptDir & "\Config.ini")
EndIf

Sleep(500)

While WinExists ("Notepad")
    Sleep(100)
Wend

$Key = IniRead(@ScriptDir & "\Config.ini", "KEY", "Key", "Blank")

HotKeySet($Key, "Toggle")

TrayTip("Program","Program is running",100,1)

While 1
    Sleep(100)
WEnd

Func Toggle()
    Send("!{TAB}")
EndFunc   ;==>Toggle
Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

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