Jump to content

How to activate a function with a MouseWheel?


Crista
 Share

Recommended Posts

How I am new to this Autoit and I am trying to activate a function using MouseWheel up command but it doesnt work?

HotKeySet("MouseWheel "up", "A")

While 1

Sleep(50)

WEnd

Func A()

Send("{ALTDOWN}")

Sleep(30)

MouseClick("left")

Sleep(30)

Send("{ALTUP}")

EndFunc ;==>A

I have tried googling this but with no result :)

Could you help please?

Link to comment
Share on other sites

Read autoit help about function _IsPressed maybe this will help...

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1

If _IsPressed("04", $dll) Then

A()

EndIf

WEnd

DllClose($dll)

Func A()

Send("{ALTDOWN}")

Sleep(30)

MouseClick("left")

Sleep(30)

Send("{ALTUP}")

EndFunc ;==>A

========

01 Left mouse button

02 Right mouse button

04 Middle mouse button (three-button mouse)

05 Windows 2000/XP: X1 mouse button

06 Windows 2000/XP: X2 mouse button

========

I don't think that you can hook mouse wheel so simple like you did // HotKeySet("MouseWheelup", "A")

[RU] Zone
Link to comment
Share on other sites

Hi,

try this....

guicreate("")
GUIRegisterMsg(0x020A, "_Mousewheel") 
guisetstate()

do
    sleep(50)
until guigetmsg()=-3    


Func _Mousewheel($hWnd, $msg, $l, $r) ;abfrage mausrad
    If $l = 0xFF880000 Then ; Mouse wheel up
        tooltip("Mousewheel up")
    Else ; Mouse wheel down
        tooltip("Mousewheel down")
    EndIf
    sleep (1000)
    tooltip("")
EndFunc   ;==>_Mousewheel

Andy

Link to comment
Share on other sites

Hi,

try this....

guicreate("")
GUIRegisterMsg(0x020A, "_Mousewheel") 
guisetstate()

do
    sleep(50)
until guigetmsg()=-3    


Func _Mousewheel($hWnd, $msg, $l, $r) ;abfrage mausrad
    If $l = 0xFF880000 Then ; Mouse wheel up
        tooltip("Mousewheel up")
    Else ; Mouse wheel down
        tooltip("Mousewheel down")
    EndIf
    sleep (1000)
    tooltip("")
EndFunc   ;==>_Mousewheel

Andy

Thanks you all for quick reply's, but where do I put all that?! When I run that macro a new Autoit window box opens but its all black? Edited by Crista
Link to comment
Share on other sites

Sorry, but this was only an example  :)

You have to replace your code into the function....but now i see, my Function only works when the window is activated.

I am looking for a solution without any GUI, something with Hooks maybe^^. I will post it here if i find something.....

Andy

/*EDIT*/ ...    If I had carefully read the first post, i had realized that not the WHEELUP (turning the Mousewheel) was mentioned, but the WHEELKLICK   :P. Sorry....

But here is my Script using _WinAPI_SetWindowsHookEx() to catch a turning Mousewheel without any GUI and it hopefully does what Crista needs^^ :)

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

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

Opt('MustDeclareVars', 1)

Global $hHook, $hStub_MouseProc, $buffer = "", $hmod

    $hStub_MouseProc = DllCallbackRegister("_MouseWheel", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), $hmod)

    While 1
        Sleep(10)
    WEnd

Func OnAutoItExit(); use it when exit ^^
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_MouseProc)
EndFunc   ;==>OnAutoItExit

Func _Mousewheel($nCode, $wParam, $lParam) ;abfrage mausrad

    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $wParam = ' & $wParam & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

; look for the  $wParam to get the number of the buttons
switch $wparam
    case 522  ; Mouse wheel up/down , i dont know how to distinguish up and down
        tooltip("mousewheel turning...")  ;
        sleep (1000)  ;not good, better return this function as fast as possible
        tooltip("")
    case 516  
;~      tooltip("right mousebutton down...")  ;
;~      sleep(1000)
;~      tooltip("")
    case 517
;~      tooltip("right mousebutton up...")  ;
;~      sleep(1000)
;~      tooltip("") 
    case 519  ;mousewheelclick^^
        Send("{ALTDOWN}")
        Sleep(30)
        MouseClick("left")
        Sleep(30)
        Send("{ALTUP}")
endswitch       
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc

Edited by AndyG
Link to comment
Share on other sites

  • 8 months later...

Func _Mousewheel($hWnd, $msg, $l, $r) ;abfrage mausrad

Im confused how do I call these functions? what do i put in the params????????

Edited by Dim
Link to comment
Share on other sites

  • Moderators

Dim,

Welcome to the AutoIt forum. :blink:

what do i put in the params?

You put nothing there, Windows does it for you! :P

GUIRegisterMsg and the message handling functions are not simple to understand. Try reading the tutorial in the Wiki and see if it all becomes clear.

Come back and ask further questions if not. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...