Jump to content
Sign in to follow this  
UQOII

Mouse wheel

Recommended Posts

UQOII

in my script stands

While _ispressed(02) ;Right mousebutton

but i need something to recive the mouse wheel action.

so if i scroll up $i = $i + 1

and if i scroll down $i = $i - 1


[center]uqoii.nl[/center]

Share this post


Link to post
Share on other sites
UQOII

i found on internet the support from microsoft

this program recognize the mousewheel up and down scrolling

i hope it helps, i cant figure it out

Edited by UQOII

[center]uqoii.nl[/center]

Share this post


Link to post
Share on other sites
UQOII

#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Const $WH_CALLWNDPROC     = 4
Global Const $WH_CALLWNDPROCRET  = 12
Global Const $WH_CBT             = 5
Global Const $WH_DEBUG         = 9
Global Const $WH_FOREGROUNDIDLE  = 11
Global Const $WH_GETMESSAGE   = 3
Global Const $WH_JOURNALPLAYBACK = 1
Global Const $WH_JOURNALRECORD   = 0
Global Const $WH_KEYBOARD       = 2
Global Const $WH_KEYBOARD_LL     = 13
Global Const $WH_MOUSE         = 7
Global Const $WH_MOUSE_LL       = 14
Global Const $WH_MSGFILTER     = -1
Global Const $WH_SHELL         = 10
Global Const $WH_SYSMSGFILTER   = 6

Global Const $KF_EXTENDED   = 0x100
Global Const $KF_ALTDOWN     = 0x2000
Global Const $KF_UP       = 0x8000
Global Const $LLKHF_EXTENDED = BitShift($KF_EXTENDED, 8)
Global Const $LLKHF_INJECTED = 0x10
Global Const $LLKHF_ALTDOWN  = BitShift($KF_ALTDOWN, 8)
Global Const $LLKHF_UP     = BitShift($KF_UP, 8)

; #STRUCTURE# ====================================================================================================


;===============
; Name...........: $tagKBDLLHOOKSTRUCT
; Description ...: Contains information about a low-level keyboard input event
; Fields ........: vkCode              - Specifies a virtual-key code. The code must be a value in the range 1 to 254
;                 scanCode           - Specifies a hardware scan code for the key
;                 flags             - Specifies the extended-key flag, event-injected flag, context code, and transition-state flag. This member is specified as follows.
;                 +  An application can use the following values to test the keystroke flags:
;                 |$LLKHF_EXTENDED   - Test the extended-key flag
;                 |$LLKHF_INJECTED   - Test the event-injected flag
;                 |$LLKHF_ALTDOWN     - Test the context code
;                 |$LLKHF_UP           - Test the transition-state flag
;                 |  0    - Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad
;                 | The value is 1 if the key is an extended key; otherwise, it is 0
;                 |  1 to 3 - Reserved
;                 |  4    - Specifies whether the event was injected. The value is 1 if the event was injected; otherwise, it is 0
;                 |  5    - Specifies the context code. The value is 1 if the ALT key is pressed; otherwise, it is 0
;                 |  6    - Reserved
;                 |  7    - Specifies the transition state. The value is 0 if the key is pressed and 1 if it is being released
;                 time               - Specifies the time stamp for this message, equivalent to what GetMessageTime would return for this message
;                 dwExtraInfo         - Specifies extra information associated with the message
; Author ........: Gary Frost (gafrost)
; Remarks .......:
; ====================================================================================================


;===========================
Global Const $tagKBDLLHOOKSTRUCT = "dword vkCode;dword scanCode;dword flags;dword time;ulong_ptr dwExtraInfo"

Global $hHook
Global $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
Global $hmod = _WinAPI_GetModuleHandle(0)
Global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
Global $buffer = ""

MsgBox(4096, "", "Click OK, then open notepad and type..." & _
        @LF & @LF & "Jon" & @LF & "AutoIt")


While 1
    Sleep(10)
WEnd

Func EvaluateKey($keycode)
    If (($keycode > 64) And ($keycode < 91)) _; A - Z
            Or (($keycode > 47) And ($keycode < 58)) Then; 0 - 9
        $buffer &= Chr($keycode)
        Switch $buffer
            Case "Jon"
                ToolTip("What can you say?")
            Case "AUTOIT"
                ToolTip("AutoIt Rocks")
        EndSwitch
    ElseIf ($keycode > 159) And ($keycode < 164) Then
        Return
    ElseIf ($keycode = 27) Then; esc key
        Exit
    Else
        $buffer = ""
    EndIf
EndFunc  ;==>EvaluateKey

;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
    Else
        Local $flags = DllStructGetData($tKEYHOOKS, "flags")
        Switch $flags
            Case $LLKHF_ALTDOWN
                ConsoleWrite("$LLKHF_ALTDOWN" & @LF)
            Case $LLKHF_EXTENDED
                ConsoleWrite("$LLKHF_EXTENDED" & @LF)
            Case $LLKHF_INJECTED
                ConsoleWrite("$LLKHF_INJECTED" & @LF)
            Case $LLKHF_UP
                ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @LF)
        EndSwitch
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc  ;==>_KeyProc

Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc  ;==>OnAutoItExit

; #FUNCTION# ====================================================================================================


;================
; Name...........: _WinAPI_UnhookWindowsHookEx
; Description ...: Removes a hook procedure installed in a hook chain by the _WinAPI_SetWindowsHookEx function
; Syntax.........: _WinAPI_UnhookWindowsHookEx($hhk)
; Parameters ....: $hhk - Handle to the hook to be removed
; Return values .: Success    - True
;                 Failure     - False
; Author ........: Gary Frost
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........; @@MsdnLink@@ UnhookWindowsHookEx
; Example .......;
; ====================================================================================================


;===========================
Func _WinAPI_UnhookWindowsHookEx($hhk)
    Local $iResult = DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hhk)
    If @error Then Return SetError(@error, @extended, 0)
    Return $iResult[0] <> 0
EndFunc  ;==>_WinAPI_UnhookWindowsHookEx

; #FUNCTION# ====================================================================================================


;================
; Name...........: _WinAPI_CallNextHookEx
; Description ...: Passes the hook information to the next hook procedure in the current hook chain
; Syntax.........: _WinAPI_CallNextHookEx($hhk, $iCode, $wParam, $lParam)
; Parameters ....: $hhk - Windows 95/98/ME: Handle to the current hook. An application receives this handle as a result of a previous call to the _WinAPI_SetWindowsHookEx function.
;                 |Windows NT/XP/2003: Ignored
;                 $iCode - Specifies the hook code passed to the current hook procedure. The next hook procedure uses this code to determine how to process the hook information
;                 $wParam  - Specifies the wParam value passed to the current hook procedure.
;                 |The meaning of this parameter depends on the type of hook associated with the current hook chain
;                 $lParam - Specifies the lParam value passed to the current hook procedure.
;                 |The meaning of this parameter depends on the type of hook associated with the current hook chain
; Return values .: Success    - This value is returned by the next hook procedure in the chain
;                 Failure     - -1 and @error is set
; Author ........: Gary Frost
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........; @@MsdnLink@@ CallNextHookEx
; Example .......;
; ====================================================================================================


;===========================
Func _WinAPI_CallNextHookEx($hhk, $iCode, $wParam, $lParam)
    Local $iResult = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hhk, "int", $iCode, "wparam", $wParam, "lparam", $lParam)
    If @error Then Return SetError(@error, @extended, -1)
    Return $iResult[0]
EndFunc  ;==>_WinAPI_CallNextHookEx

; #FUNCTION# ====================================================================================================


;================
; Name...........: _WinAPI_SetWindowsHookEx
; Description ...: Installs an application-defined hook procedure into a hook chain
; Syntax.........: _WinAPI_SetWindowsHookEx($idHook, $lpfn, $hmod[, $dwThreadId = 0])
; Parameters ....: $idHook  - Specifies the type of hook procedure to be installed. This parameter can be one of the following values:
;                 |$WH_CALLWNDPROC   - Installs a hook procedure that monitors messages before the system sends them to the destination window procedure
;                 |$WH_CALLWNDPROCRET  - Installs a hook procedure that monitors messages after they have been processed by the destination window procedure
;                 |$WH_CBT           - Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application
;                 |$WH_DEBUG           - Installs a hook procedure useful for debugging other hook procedures
;                 |$WH_FOREGROUNDIDLE  - Installs a hook procedure that will be called when the application's foreground thread is about to become idle
;                 |$WH_GETMESSAGE     - Installs a hook procedure that monitors messages posted to a message queue
;                 |$WH_JOURNALPLAYBACK - Installs a hook procedure that posts messages previously recorded by a $WH_JOURNALRECORD hook procedure
;                 |$WH_JOURNALRECORD   - Installs a hook procedure that records input messages posted to the system message queue
;                 |$WH_KEYBOARD     - Installs a hook procedure that monitors keystroke messages
;                 |$WH_KEYBOARD_LL   - Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events
;                 |$WH_MOUSE           - Installs a hook procedure that monitors mouse messages
;                 |$WH_MOUSE_LL     - Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events
;                 |$WH_MSGFILTER       - Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar
;                 |$WH_SHELL           - Installs a hook procedure that receives notifications useful to shell applications
;                 |$WH_SYSMSGFILTER - Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar
;                 $lpfn  - Pointer to the hook procedure. If the $dwThreadId parameter is zero or specifies the identifier of a thread created by a different process,
;                 + the $lpfn parameter must point to a hook procedure in a DLL.
;                 |Otherwise, $lpfn can point to a hook procedure in the code associated with the current process
;                 $hmod  - Handle to the DLL containing the hook procedure pointed to by the $lpfn parameter.
;                 |The $hMod parameter must be set to NULL if the $dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the
;                 + code associated with the current process
;                 $dwThreadId - Specifies the identifier of the thread with which the hook procedure is to be associated.
;                 |If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread
; Return values .: Success    - Handle to the hook procedure
;                 Failure     - 0 and @error is set
; Author ........: Gary Frost
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........; @@MsdnLink@@ SetWindowsHookEx
; Example .......;
; ====================================================================================================


;===========================
Func _WinAPI_SetWindowsHookEx($idHook, $lpfn, $hmod, $dwThreadId = 0)
    Local $hwndHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $idHook, "ptr", $lpfn, "hwnd", $hmod, "dword", $dwThreadId)
    If @error Then Return SetError(@error, @extended, 0)
    Return $hwndHook[0]
EndFunc  ;==>_WinAPI_SetWindowsHookEx

So this is the code. The problem is that it only for keyboard. How do i set this for the mouse? ive tried this but i dont get it worked :)


[center]uqoii.nl[/center]

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  

×