Jump to content

_isPressed question


nick21
 Share

Recommended Posts

I was wondering is it possible to use the _ispressed command with scroll up and scroll down function on the mouse.

All I want it to do is detect when the mouse scrolls up and when the mouse scrolls down.

I looked thru all the _ispressed commands, but don't see a number for that mousescroll up, and mousescroll down.

I also tried this with no luck:

#include <Misc.au3>
$dll = DllOpen("user32.dll")



While 1
    
    If _IsPressed(MouseWheel("up")) Then
        MsgBox(0,"WheelUp", "WheelUp")
        ExitLoop
    EndIf
WEnd


DllClose($dll)
Link to comment
Share on other sites

If its in a GUI then it can be done with GUIRegisterMsg.

WM_MOUSEWHEEL = 0x020A

an example that is probably quite hard to read:

GUICreate("Testing mouse wheel")

Global $hLbl = GUICtrlCreateLabel("0", 2, 2, 100, 20)

GUISetState (@SW_SHOW)
GUIRegisterMsg (0x020A , "WM_MOUSEWHEEL")

While GUIGetMsg() <> -3
    Sleep(10)
WEnd

Func WM_MOUSEWHEEL($hWnd, $msgId, $wParam, $lParam)
    GUICtrlSetData($hLbl, GUICtrlRead($hLbl) + (BitShift($wParam, 16) / 120))
EndFunc   ;==>WM_MOUSEWHEEL

As an explanation: BitSHIFT ($wParam, 16) will return the high order word of wParam, which MSDN says:

The high-order word indicates the distance the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.

It is then divided by 120 to give you +1 or -1 for each turn. Not a particularly glamorous example, and there will almost certainly be flickering, but it does the job.

Mat

Edit: It triggers the message when the GUI is the active window. The cursor does not need to be above the window itself. However, if a control with a scrollbar is focused, it will swallow the message, as shown here:

GUICreate("Testing mouse wheel")

Global $hLbl = GUICtrlCreateLabel("0", 2, 2, 100, 20)

GUICtrlCreateInput ("", 104, 2, 100, 20)
GUICtrlCreateEdit ("", 2, 24, 200, 200)

For $i = 1 To 100
    GUICtrlSetData (-1, "test" & @CRLF, 1)
Next

GUISetState (@SW_SHOW)
GUIRegisterMsg (0x020A , "WM_MOUSEWHEEL")

While GUIGetMsg() <> -3
    Sleep(10)
WEnd

Func WM_MOUSEWHEEL($hWnd, $msgId, $wParam, $lParam)
    GUICtrlSetData($hLbl, GUICtrlRead($hLbl) + (BitShift($wParam, 16) / 120))
EndFunc   ;==>WM_MOUSEWHEEL

When the large edit is focused, the label will not increment. Focus the input to let it capture the message again.

Edited by Mat
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...