Sign in to follow this  
Followers 0
GarrettHylltun

Catch Multimedia Key Presses?

6 posts in this topic

Is it possible with AutoIT to catch the key presses from the multimedia keys, such as Play, Pause, Vol Up, Mute etc...? Err, at least on XP and up that is.

Thanks,

~Garrett

Share this post


Link to post
Share on other sites



Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I think that you may use _IsPressed().

7C-7F (F13 key - F16 key)

80H-87H (F17 key - F24 key)

Edited by Andreik

When the words fail... music speaks

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  
Followers 0