Sign in to follow this  
Followers 0
TheReveller

Missing Keys

5 posts in this topic

Hello,

I used AutoHotkey and I think that AutoIt has more options and I was wondering why in AutoHotkey I can easily do track/send WheelUp/WheelDown/XButton1/XButton2, but I can't do this in AutoIt if I don't use some crazy code I don't understand.

I mean, the UDF _IsPressed is great and better than KeyWait from AutoHotkey, but I can't find an easy way to know if the mouse wheel has been turned up or down to do +1/-1 to a variable.

I think that feature should be in AutoIt.

Thanks.

By the way, if you could post me some little function that would return 1 when I ask if there is wheel up (and 0 for all others, including wheel down) and would also return 1 when I ask if there is wheel down (and 0 for all others, including wheel up), that would be gentle.

Many thanks.

Share this post


Link to post
Share on other sites



#include <WinAPI.au3>

Dim Const $WM_NCXBUTTONDOWN     = 0x00AB
Dim Const $WM_NCXBUTTONUP       = 0x00AC
Dim Const $WM_NCXBUTTONDBLCLK   = 0x00AD
Dim Const $WM_MOUSEWHEEL        = 0x020A
Dim Const $WM_XBUTTONDOWN       = 0x020B
Dim Const $WM_XBUTTONUP         = 0x020C
Dim Const $WM_XBUTTONDBLCLK     = 0x020D
Dim Const $WM_MOUSELAST         = 0x020A

Dim Const $tagMSLLHOOKSTRUCT = $tagPOINT&';dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo'

HotKeySet('{ESC}', '_EXIT')

$hFunc = DllCallbackRegister("Mouse_LL", "long", "int;wparam;lparam")
$pFunc = DllCallbackGetPtr($hFunc)
$hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pFunc, _WinAPI_GetModuleHandle(0))

While 1
    sleep(100)
WEnd


Func _EXIT()
    Exit
EndFunc


Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hFunc)
EndFunc


Func Mouse_LL($iCode, $iwParam, $ilParam)
    Local $tMSLLHOOKSTRUCT = DllStructCreate($tagMSLLHOOKSTRUCT, $ilParam)
    
    If $iCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
    EndIf
    
    If $iwParam = $WM_MOUSEWHEEL Then
        Local $iValue = DllStructGetData($tMSLLHOOKSTRUCT, 'mouseData')/2^16
        If BitAND($iValue, 0x8000) Then $iValue = BitOR($iValue, 0xFFFF0000)
        
        ConsoleWrite('WM_MOUSEWHEEL => delta:' & @TAB)
        ConsoleWrite($iValue & @LF)
    EndIf
        
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc   ;==>_KeyProc

$iwParam is holding one of the header variable messages including the other messages for mouse event that are defined in the include "WindowsConstants.au3". If you're interested to process only messages that posted on your GUI window then it's better to use GUIRegisterMsg instead.

Share this post


Link to post
Share on other sites

Thanks, but that's really out of my knowledge, I don't understand anything of that code.

All I wish is a function that I call and returns me 0 or 1.

Example :

If MouseWheelUp() Then

...

EndIf

If MouseWheelDown() Then

...

EndIf

MouseWheelUp() becomes true for every 1 scroll up and MouseWheelDown() becomes true for every 1 scroll down.

Now, how to do those kind of functions, I really don't know. I'm trying to create a small program useful to me, but I'm not a programmer. All I know are basics, building strong logic & maths and still trying to learn more, but Dll and such things are out of my knowledge, sorry. I don't even know what Dll are used for...

Thanks.

Share this post


Link to post
Share on other sites

Well, the developers aren't writing special functions that are sanely available. If you don't understand you can read about these functions posted on MSDN site to get better understanding, otherwise you can do the GUIRegisterMsg thing if you're interested in events posted only on your window.

By the way, it's not hard to something like

Dim Const $WM_NCXBUTTONDOWN  = 0x00AB
Dim Const $WM_NCXBUTTONUP       = 0x00AC
Dim Const $WM_NCXBUTTONDBLCLK   = 0x00AD
Dim Const $WM_MOUSEWHEEL        = 0x020A
Dim Const $WM_XBUTTONDOWN      = 0x020B
Dim Const $WM_XBUTTONUP      = 0x020C
Dim Const $WM_XBUTTONDBLCLK  = 0x020D
Dim Const $WM_MOUSELAST      = 0x020A
.
..
...


Func Mouse_LL($iCode, $iwParam, $ilParam)
    Local $tMSLLHOOKSTRUCT = DllStructCreate($tagMSLLHOOKSTRUCT, $ilParam)
   
    If $iCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
    EndIf
   
    Switch $iwParam
        Case $WM_MOUSEWHEEL
            onmousewheel()
            
        Case $WM_XBUTTONDBLCLK
            OnXButtonDlClk()
            
        Case $WM_XBUTTONDOWN
            OnXButtonDown()
            
        Case $WM_NCXBUTTONUP
            OnXButtonUp()
    EndSwitch
       
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc   ;==>Mouse_LL


Func onmousewheel()
    ; Code to return coordinates, etc.
EndFunc

Func OnXButtonDlClk()
    ; Code to return coordinates, etc.
EndFunc

Func OnXButtonDown()
    ; Code to return coordinates, etc.
EndFunc

Func OnXButtonUp()
    ; Code to return coordinates, etc.
EndFunc

Share this post


Link to post
Share on other sites

Ah ok, sorry I just didn't understand your first script because of this :

ConsoleWrite('WM_MOUSEWHEEL => delta:' & @TAB)

ConsoleWrite($iValue & @LF)

I couldn't see any result because I don't know how it works, so I thought I had to call some function but I didn't know how but if I do :

MsgBox(48, "", "WM_MOUSEWHEEL => delta:" & $iValue)

Now I see how the value is returned.

Thank you.

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