Sign in to follow this  
Followers 0
milkman

Problem with looping

5 posts in this topic

Here is my scirpt.

; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.1.0

; Author: Calvin <teamgonuts@gmail.com>

;

; Script Function:

; Opens CD Tray

; Closes CD Tray

; ----------------------------------------------------------------------------

; Script Start - Add your code below here

AutoItSetOption( "TrayIconHide" , 1 )

HotKeySet ( "\" , "close" )

Func close ()

Exit

EndFunc

$m = 1

While $m = 1

HotKeySet ( "m" , "opencd" )

WEnd

Func opencd ()

CDTray ( "D:", "open" )

$m = 2

EndFunc

While $m = 2

HotKeySet ( "m" , "closecd")

WEnd

Func closecd ()

CDTray ("D:" , "close" )

$m = 1

EndFunc

While 1=1

Sleep (100)

WEnd

I hit 'm' once, the CD Tray opens.

I hit 'm' again, the CD tray closes.

I hit 'm' a third time, and instead of opening the CD tray again, nothing happens. What am I doing wrong?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Global $CDTray
HotKeySet("{ESC}", "Terminate")
HotKeySet("m", "ShowMessage")  

;;;; Body of program would go here;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    If $CDTray Then CDTray ( "d:", "close" )
    If Not $CDTray Then CDTray ( "d:", "open" )
    $CDTray = NOT $CDTray
EndFunc

Code borrowed and edited. Originally written by Valuater.

Edited by Oxin8

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

after the second "close" .. $m =1 and goes to the next position

While 1=1

Sleep (100) ; while you are here... nothing happens

WEnd

.............

You should not place any "creates" inside a loop

While $m = 2

HotKeySet ( "m" , "closecd")

WEnd

this sets the hot key over and over and over and....

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

after the second "close" .. $m =1 and goes to the next position

While 1=1

Sleep (100) ; while you are here... nothing happens

WEnd

.............

You should not place any "creates" inside a loop

While $m = 2

HotKeySet ( "m" , "closecd")

WEnd

this sets the hot key over and over and over and....

8)

So how can I fix this?

Share this post


Link to post
Share on other sites

So how can I fix this?

Just use the code that Oxin8 gave above

8)


NEWHeader1.png

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