Jump to content
Sign in to follow this  
jzn2

multi optical drive hotkey eject

Recommended Posts

jzn2

I have been working on a script that would support multiple drive hotkey for open and close functions... However i ran into a problem and dont quite understand the language... Some help would be apreciated.. Here is the code:

Optical_Drive_Open_close_hotkeys.au3

; Place at the top of your script
; Allows only one instance of this script
$g_szVersion = "CD Hotkey B1"
If WinExists($g_szVersion) Then Exit ; It's already running
AutoItWinSetTitle($g_szVersion)
; Rest of your script goes here
Select 

    Case HotKeySet("^!1") then ;CTRL+ALT+1
        $d = DriveGetDrive("CDROM"); close all optical drives
        For $x = 1 to $d[0]
            CDTray($d[$x],"close")
        EndIf
        Next
    Case HotKeySet("^!2") then ;CTRL+ALT+2
        $d = DriveGetDrive("CDROM"); Open all Optical Drives
        For $x = 1 to $d[0]
            CDTray($d[$x],"open")
        EndIf
        Next
    Case HotKeySet("^!3") then ;CTRL+ALT+3
        $d = DriveGetDrive("CDROM")
        For $x = 1 to $d[0]; Open all Optical Drives
            if DriveStatus($d[$x]) = "NOTREADY" then
                $test = CDTray($d[$x],"open")
        EndIf
        Next
        For $x = 1 to $d[0]; close all optical drives
            if DriveStatus($d[$x]) = "NOTREADY" then
                $test = CDTray($d[$x],"close")
        EndIf
        Next
    Case HotKeySet("^!4") then ;CTRL+ALT+4
        CDTray("F:", "open"); Open the CD tray on drive F:
        EndIf

[edit] this is a non functioning example. Working example below [/edit]

Edited by jzn2

Share this post


Link to post
Share on other sites
jvanegmond

Case HotKeySet("^!1") then ;CTRL+ALT+1

That's is the strangest case of HotKeySet I have seen ever!

You probably want to take another look at HotKeySet in the helpfile.

Edited by Manadar

Share this post


Link to post
Share on other sites
jzn2

Your right that helped alot! Thanks!

Edited by jzn2

Share this post


Link to post
Share on other sites
jzn2

Here we go This works alot better! maybe i should move this to scripts and scraps section

; Place at the top of your script
; Allows only one instance of this script
$g_szVersion = "CD Hotkey B2"
If WinExists($g_szVersion) Then Exit ; It's already running
AutoItWinSetTitle($g_szVersion)
; Rest of your script goes here

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("+{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage")  ;Shift-Alt-d
HotKeySet("^!1", "AllClose")  ;CTRL+ALT+1
HotKeySet("^!2", "AllOpen")  ;CTRL+ALT+2
HotKeySet("^!3", "AllTest")  ;CTRL+ALT+3
HotKeySet("^!4", "FClose")  ;CTRL+ALT+4

;sleep
While 1
    Sleep(100)
WEnd


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

Func AllClose()
    $d = DriveGetDrive("CDROM")  ; close all optical drives
    For $x = 1 to $d[0]
        CDTray($d[$x],"close")
    Next
EndFunc

Func AllOpen()
    $d = DriveGetDrive("CDROM")  ; Open all Optical Drives
    For $x = 1 to $d[0]
        CDTray($d[$x],"open")
    Next
EndFunc

Func AllTest()
    $d = DriveGetDrive("CDROM")
    For $x = 1 to $d[0]  ; Open all Optical Drives
        if DriveStatus($d[$x]) = "NOTREADY" then
            $test = CDTray($d[$x],"open")
    EndIf
    Next
    For $x = 1 to $d[0]  ; close all optical drives
        if DriveStatus($d[$x]) = "NOTREADY" then
            $test = CDTray($d[$x],"close")
    EndIf
    Next
EndFunc

Func FClose()
    CDTray("F:", "open")  ; Open the CD tray on drive F:
    EndFunc

Share this post


Link to post
Share on other sites
jzn2

Is there another way to refer to a specific cd drive without calling the drive letter?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.