ÿþPublic Class Form1 ' Registering hotkeys Private Declare Unicode Function RegisterHotKey Lib "user32.dll" _ (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifier As Integer, ByVal vk As Integer) As Integer ' Media center interface? this is for sending open/close CD door messages. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long 'Enumerating the various mod keys (alt, ctrl, shift, windows) Private Enum rhk As Integer MOD_ALT = 1 MOD_CONTROL = 2 MOD_SHIFT = 4 MOD_WIN = 8 End Enum ' Private constants for hotkeys. Private Const hkID As Integer = 1 Private Const VK_F12 As Integer = &H7B Private Const WM_HOTKEY As Integer = &H312 ' mainly for the CD drive functions below. Dim lRet As Long 'Registering hotkeys on FORM LOAD Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load RegisterHotKey(Me.Handle, hkID, rhk.MOD_CONTROL, VK_F12) If RegisterHotKey(Me.Handle, hkID, rhk.MOD_CONTROL, VK_F12) = 0 Then Label1.Text = "Failed to Register Hot Key." End If End Sub Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Static xCount As Integer = 0 If m.Msg = WM_HOTKEY Then xCount += 1 Label1.Text = "Ping " & xCount.ToString Debug.WriteLine(m.ToString) If RegisterHotKey(Me.Handle, hkID, rhk.MOD_CONTROL, VK_F12) = 1 Then If lRet = "CD drive open" Then ClosetheCDtray() Else OpentheCDtray() End If End If End If MyBase.WndProc(m) End Sub 'Private Sub cmdOpenCD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdOpenCD.Click Public Function OpentheCDtray() lRet = mciSendString("set CDAudio door open", "CD drive open", 127, 0) 'End Sub Return 1 End Function 'Private Sub cmdCloseCD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCloseCD.Click Public Function ClosetheCDtray() lRet = mciSendString("set CDAudio door closed", "CD drive close", 127, 0) 'End Sub Return 0 End Function '======================================================= ' This section is solely for unregistering all hotkeys. '======================================================= Private Declare Unicode Function UnregisterHotKey Lib "user32.dll" _ (ByVal hWnd As IntPtr, ByVal id As Integer) As Integer Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing If UnregisterHotKey(Me.Handle, hkID) = 0 Then Debug.Print("Failed to unregister hot hey") End If End Sub End Class