Jump to content

Open & Close CDTray with Hotkey...


stingjoel
 Share

Recommended Posts

Thanks to ezzetabi...with function _IsPressed, you can open or close all CDROM you have by clicking hotkeys...

If you have 2 CDROM, just press:

- WIN+O then 1 to open 1st CDROM, press WIN+C then 1 to close it

- WIN+O then 2 to open 2nd CDROM, press WIN+C then 2 to close it...

If you have 9 CDROM and you want to open 5th CDROM, just press WIN+O then 5....press WIN+C then 5 to close it...:)

This script is limited to 9 CDROMs (I'll be amaze if you have 9 CDROM on your computer :)) but if you have more than 9 CDROMS, you can modify it for you requirement...

; ----------------------------------------------------------------------------
; Include
; ----------------------------------------------------------------------------
#include <_IfPressed.au3>

; ----------------------------------------------------------------------------
; HotKeySet
; ----------------------------------------------------------------------------
Hotkeyset("#o", "OpenCDTray")
Hotkeyset("#c", "CloseCDTray")
HotKeySet("#!{ESC}", "Quit")

; ----------------------------------------------------------------------------
; Initialize
; ----------------------------------------------------------------------------
Global $FlagCDTray = "False", $CountCDTray = 0, $StatusCDTray

; ----------------------------------------------------------------------------
; Looping Process
; ----------------------------------------------------------------------------
While 1
  If $FlagCDTray = "True" Then
     $CountCDTray = $CountCDTray + 1

     For $X = 31 to 39
         If _IsPressed(String($X)) Then
            $FlagCDTray = "False"
            $CountCDTray = 0
            OpenCloseCDTray($X - 30)
            ExitLoop
         EndIf
     Next

     If ($CountCDTray >= 10) Then
        $FlagCDTray = "False"
        $CountCDTray = 0
     EndIf
  Endif

  Sleep(100)
WEnd

; ----------------------------------------------------------------------------
; Function OpenCDTray
; ----------------------------------------------------------------------------
Func OpenCDTray()
     $FlagCDTray = "True"
     $StatusCDTray = "Open"
EndFunc

; ----------------------------------------------------------------------------
; Function CloseCDTray
; ----------------------------------------------------------------------------
Func CloseCDTray()
     $FlagCDTray = "True"
     $StatusCDTray = "Close"
EndFunc

; ----------------------------------------------------------------------------
; Function OpenCloseCDTray
; ----------------------------------------------------------------------------
Func OpenCloseCDTray($Number)
    ;MsgBox(64, "", $Number)
     $CDROM = DriveGetDrive("CDROM")
     If NOT @error Then
        If ($Number <= $CDROM[0]) then
           If $StatusCDTray = "Close" Then
              CDTray($CDROM[$Number], "closed")
           Else
              CDTray($CDROM[$Number], "open")
           EndIf
        EndIf
     EndIf
EndFunc

; ----------------------------------------------------------------------------
; Function Quit
; ----------------------------------------------------------------------------
Func Quit()
     $Result = MsgBox(308, "Warning", "This Utility will be terminated" & @CRLF & "  A r e   y o u   s u r e ?")
     If $Result = 6 Then
        Exit
     EndIf
EndFunc
Link to comment
Share on other sites

neat, but u could just do this too!

While 1
HotKeySet ("^!o", "Open")
WEnd
Func Open ()
   CDTray ("E:", "open")
EndFunc

just a pointer...

EDIT: also, to close...

While 1
HotKeySet ("^!o", "Open")
HotKeySet ("^!p", "Close")
WEnd
Func Open ()
   CDTray ("E:", "open")
EndFunc

Func Close()
   CDTray ("E:", "Close")
   EndFunc

but anyways, neat little script you made :)

Edited by layer
FootbaG
Link to comment
Share on other sites

Your script is great and simple if you have only 1 CDROM...if you have 100 CDROMs (yeah...yeah I know it is imposible :(), how long will your script be? :):)

Btw, I think....it is not necessary placing Hotkeyset in while WEnd loop... ;):D

Sorry for my bad english :idiot::idiot:

neat, but u could just do this too!

While 1
HotKeySet ("^!o", "Open")
WEnd
Func Open ()
   CDTray ("E:", "open")
EndFunc

just a pointer...

EDIT: also, to close...

While 1
HotKeySet ("^!o", "Open")
HotKeySet ("^!p", "Close")
WEnd
Func Open ()
   CDTray ("E:", "open")
EndFunc

Func Close()
   CDTray ("E:", "Close")
   EndFunc

but anyways, neat little script you made :idiot:

<{POST_SNAPBACK}>

Edited by stingjoel
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...