Skip to content

Instantly share code, notes, and snippets.

@imryan
Last active December 30, 2015 08:49
Show Gist options
  • Save imryan/7805040 to your computer and use it in GitHub Desktop.
Save imryan/7805040 to your computer and use it in GitHub Desktop.
Opens and closes disk tray infinitely.
import ctypes
def eject():
opens = 0
closes = 0
while (True):
# Open disk tray
ctypes.windll.WINMM.mciSendStringW(u"open D: type cdaudio alias d_drive", None, 0, None)
ctypes.windll.WINMM.mciSendStringW(u"set d_drive door open", None, 0, None)
opens += 1
if (opens is 1):
print "OPENED:", opens, "TIME"
print '\a'
else:
print "OPENED:", opens, "TIMES"
print '\a'
# Close disk tray
ctypes.windll.WINMM.mciSendStringW(u"set d_drive door closed", None, 0, None)
closes += 1
if (closes is 1):
print "CLOSED:", closes, "TIME"
print '\a'
else:
print "CLOSED:", closes, "TIMES"
print '\a'
name = raw_input()
eject()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment