Jump to content

Catch Multimedia Key Presses?


Recommended Posts

Link to comment
Share on other sites

K, thanks... BTW, I didn't see that function in the help file... is it in there and I missed it?

~Garrett

It's there, under "Misc Management". You may also want to check HotKeySet() in the helpfile.
Link to comment
Share on other sites

GarrettHylltun

Try this:

Global Const $WH_KEYBOARD_LL = 13
Global Const $KEY = 257

Global Const $MMUTE = 173
Global Const $MVOLDOWN = 174
Global Const $MVOLUP = 175
Global Const $MNEXT = 176
Global Const $MPREV = 177
Global Const $MSTOP = 178
Global Const $MPLAY = 179

Global $pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
Global $hmod = DllCall("kernel32.dll","hwnd","GetModuleHandle","ptr",0)

Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", _
                        "int", $WH_KEYBOARD_LL, _
                        "ptr", DllCallbackGetPtr($pStub_KeyProc), _
                        "hwnd", $hmod[0], _
                        "dword", 0)
$hHook = $hHook[0]

While 1
    Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Local $aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook, "int", $nCode, "wparam", $wParam, _
                              "lparam", $lParam)
        Return $aRet[0]
    EndIf
    
    Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)
    
    Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")
    Local $iFlag = DllStructGetData($KBDLLHOOKSTRUCT, "flags")
    
    If $iFlag = 1 Then
        Switch $vkCode
            Case $MMUTE
                ConsoleWrite("!> Mute key pressed" & @LF)
            Case $MVOLDOWN
                ConsoleWrite("!> Vol down key pressed" & @LF)
            Case $MVOLUP
                ConsoleWrite("!> Vol up key pressed" & @LF)
            Case $MNEXT
                ConsoleWrite("!> Next key pressed" & @LF)
            Case $MPREV
                ConsoleWrite("!> Previous key pressed" & @LF)
            Case $MSTOP
                ConsoleWrite("!> Stop key pressed" & @LF)
            Case $MPLAY
                ConsoleWrite("!> Play key pressed" & @LF)
        EndSwitch
    EndIf
EndFunc

Func OnAutoItExit()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx","hwnd", $hHook)
    DllCallbackFree($pStub_KeyProc)
EndFunc
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...