Jump to content
Sign in to follow this  
IKilledBambi

Clicking Mouse4.

Recommended Posts

IKilledBambi

Search yielded about 6-7 results and most of them were _ispressed but I'm not trying to see when I'm pressing it, I'm trying to press it, has a solution to MouseClick("Mouse4") ever been found?

Share this post


Link to post
Share on other sites
KaFu

MouseClick ( "button" [, x, y [, clicks [, speed ]]] )

button = The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".

Which one is the forth?

Share this post


Link to post
Share on other sites
PsaltyDS

MouseClick ( "button" [, x, y [, clicks [, speed ]]] )

button = The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".

Which one is the forth?

I think Mouse4 and Mouse5 are thumb buttons on the left side (of a right-handed) mouse. Perhaps they map to X1 and X2 which can be detected with _IsPressed() using "05" or "06", but don't have usable names in MouseClick().

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
KaFu

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $hGUI, $GUIMsg

$hGUI = GUICreate("4th Mouth Button", 300, 200)

Global Const $WM_XBUTTONDOWN = 0x020B
GUIRegisterMsg($WM_XBUTTONDOWN, "MY_WM_XBUTTONDOWN")

GUISetState()

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

Func MY_WM_XBUTTONDOWN($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam

    ConsoleWrite($nNotifyCode & @TAB & $nID & @TAB & $hCtrl & @CRLF)

    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_XBUTTONDOWN

Shows activity in console at least for my 4th mouse button...

Share this post


Link to post
Share on other sites
PsaltyDS

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $hGUI, $GUIMsg

$hGUI = GUICreate("4th Mouth Button", 300, 200)

Global Const $WM_XBUTTONDOWN = 0x020B
GUIRegisterMsg($WM_XBUTTONDOWN, "MY_WM_XBUTTONDOWN")

GUISetState()

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

Func MY_WM_XBUTTONDOWN($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam

    ConsoleWrite($nNotifyCode & @TAB & $nID & @TAB & $hCtrl & @CRLF)

    Return $GUI_RUNDEFMSG
EndFunc  ;==>MY_WM_XBUTTONDOWN

Shows activity in console at least for my 4th mouse button...

Well, yes, but I thought he wants to automate clicking that button, not detecting when it is clicked (which _IsPressed() can do already).

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
KaFu
Malkey

Search yielded about 6-7 results and most of them were _ispressed but I'm not trying to see when I'm pressing it, I'm trying to press it, has a solution to MouseClick("Mouse4") ever been found?

Thanks to KaFu's example, I noticed the return values in the $wParam parameter are 0x00010020 for left X1 mouse button and, 0x00020040 for the right X2 mouse button.

This script was modified from here

http://www.autoitscript.com/forum/index.ph...st&p=636051

This script sends a X1 or X2 Mouse button click to the active control window. It works on my XP.

Sleep(3000); allow 3 secs to activate web browser to test jump forward,x2 or jump back with x1 mouse button send click

_MouseClickPlus(ControlGetHandle("","",""), "x2") ;  WinGetHandle("")

;
; Function Name: _MouseClickPlus()
; Version added: 0.1
; Description: Sends a click to window
; minimized.
; Parameter(s): $Window = Title of the window to send click to
; $Button = "left" or "right" mouse button
; $X = X coordinate
; $Y = Y coordinate
; $Clicks = Number of clicks to send
; Remarks: You MUST be in "MouseCoordMode" 0 to use this without bugs.
; Author(s): Insolence <insolence_9@yahoo.com>
;Modified: Malkey - Added X1 an X2 Mouse buttons and other bits.
;http://www.autoitscript.com/forum/index.php?s=&showtopic=88517&view=findpost&p=636051
;===============================================================================
Func _MouseClickPlus($hwnd, $sButton = "left", $X = "", $Y = "", $Clicks = 1)
    Local $MK_LBUTTON = 0x0001
    Local $WM_LBUTTONDOWN = 0x0201
    Local $WM_LBUTTONUP = 0x0202

    Local $MK_RBUTTON = 0x0002
    Local $WM_RBUTTONDOWN = 0x0204
    Local $WM_RBUTTONUP = 0x0205

    Global $MK_XBUTTON1 = 0x00010020; 0x20
    Global $WM_XBUTTONDOWN = 0x20B;x1Button Left side of mouse - Back
    Global $WM_XBUTTONUP = 0x20C    

    Global $MK_XBUTTON2 = 0x00020040;;x2Button right side of mouse - forward
    Global $WM_NCXBUTTONDOWN = 0x00AB
    Global $WM_NCXBUTTONUP = 0x00AC

    Local $WM_MOUSEMOVE = 0x0200

    Local $i = 0

    Select
        Case $sButton = "x2"
            $Button = $MK_XBUTTON2
            $ButtonDown = $WM_NCXBUTTONDOWN
            $ButtonUp = $WM_NCXBUTTONUP
        Case $sButton = "x1"
            $Button = $MK_XBUTTON1
            $ButtonDown = $WM_XBUTTONDOWN
            $ButtonUp = $WM_XBUTTONUP           
        Case $sButton = "left"
            $Button = $MK_LBUTTON
            $ButtonDown = $WM_LBUTTONDOWN
            $ButtonUp = $WM_LBUTTONUP
        Case $sButton = "right"
            $Button = $MK_RBUTTON
            $ButtonDown = $WM_RBUTTONDOWN
            $ButtonUp = $WM_RBUTTONUP
    EndSelect

    If $X = "" Or $Y = "" Then
        $MouseCoord = MouseGetPos()
        $X = $MouseCoord[0]
        $Y = $MouseCoord[1]
    EndIf

    For $i = 1 To $Clicks
        DllCall("user32.dll", "int", "SendMessage", "hwnd", $hwnd, "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($X, $Y))

        DllCall("user32.dll", "int", "SendMessage", "hwnd", $hwnd, "int", $ButtonDown, "int", $Button, "long", _MakeLong($X, $Y))

        DllCall("user32.dll", "int", "SendMessage", "hwnd", $hwnd, "int", $ButtonUp, "int", $Button, "long", _MakeLong($X, $Y))
    Next
EndFunc  ;==>_MouseClickPlus


Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc  ;==>_MakeLong

Share this post


Link to post
Share on other sites
KaFu

Thanks to KaFu's example, I noticed the return values in the $wParam parameter are 0x00010020 for left X1 mouse button and, 0x00020040 for the right X2 mouse button.

Really nice :) . Was more looking into the directio of SetAsyncKeyState yesterday, but it was just too late :lmao:...

Tested it a little and found that ButtonDown and ButtonUp are more like the same then different values for both buttons (see example).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $hGUI, $GUIMsg

$hGUI = GUICreate("4th Mouth Button", 300, 200,10,10)

HotKeySet("a","_MouseClickPlusX1")
HotKeySet("b","_MouseClickPlusX2")

Global Const $WM_XBUTTONDOWN = 0x020B
Global Const $MK_XBUTTON1 = 0x00010020; 0x20

GUIRegisterMsg($WM_XBUTTONDOWN, "MY_WM_XBUTTONDOWN")

GUISetState()

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

Func MY_WM_XBUTTONDOWN($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam

    ConsoleWrite($nNotifyCode & @TAB & $nID & @TAB & $hCtrl & @CRLF)

    Return $GUI_RUNDEFMSG
EndFunc  ;==>MY_WM_XBUTTONDOWN





func _MouseClickPlusX1()
    _MouseClickPlus($hGUI, "x1", "","",1)
EndFunc

func _MouseClickPlusX2()
    _MouseClickPlus($hGUI, "x2", "","",1)
EndFunc



















;Sleep(3000); allow 3 secs to activate web browser to test jump forward,x2 or jump back with x1 mouse button send click


; Function Name: _MouseClickPlus()
; Version added: 0.1
; Description: Sends a click to window
; minimized.
; Parameter(s): $Window = Title of the window to send click to
; $Button = "left" or "right" mouse button
; $X = X coordinate
; $Y = Y coordinate
; $Clicks = Number of clicks to send
; Remarks: You MUST be in "MouseCoordMode" 0 to use this without bugs.
; Author(s): Insolence <insolence_9@yahoo.com>
;Modified: Malkey - Added X1 an X2 Mouse buttons and other bits.
;http://www.autoitscript.com/forum/index.php?s=&showtopic=88517&view=findpost&p=636051
;===============================================================================
Func _MouseClickPlus($hwnd, $sButton = "left", $X = "", $Y = "", $Clicks = 1)
    Local $MK_LBUTTON = 0x0001
    Local $WM_LBUTTONDOWN = 0x0201
    Local $WM_LBUTTONUP = 0x0202

    Local $MK_RBUTTON = 0x0002
    Local $WM_RBUTTONDOWN = 0x0204
    Local $WM_RBUTTONUP = 0x0205

    Local $MK_XBUTTON1 = 0x00010020; 0x20
    Local $WM_XBUTTONDOWN = 0x20B;x1Button Left side of mouse - Back
    Local $WM_XBUTTONUP = 0x20C    

    Local $MK_XBUTTON2 = 0x00020040;;x2Button right side of mouse - forward
    Local $WM_NCXBUTTONDOWN = 0x00AB
    Local $WM_NCXBUTTONUP = 0x00AC

    Local $WM_MOUSEMOVE = 0x0200

    Local $i = 0

    Select
        Case $sButton = "x2"
            $Button = $MK_XBUTTON2
            ;$ButtonDown = $WM_NCXBUTTONDOWN
            ;$ButtonUp = $WM_NCXBUTTONUP
            $ButtonDown = $WM_XBUTTONDOWN
            $ButtonUp = $WM_XBUTTONUP                       
        Case $sButton = "x1"
            $Button = $MK_XBUTTON1
            $ButtonDown = $WM_XBUTTONDOWN
            $ButtonUp = $WM_XBUTTONUP            
        Case $sButton = "left"
            $Button = $MK_LBUTTON
            $ButtonDown = $WM_LBUTTONDOWN
            $ButtonUp = $WM_LBUTTONUP
        Case $sButton = "right"
            $Button = $MK_RBUTTON
            $ButtonDown = $WM_RBUTTONDOWN
            $ButtonUp = $WM_RBUTTONUP
    EndSelect

    If $X = "" Or $Y = "" Then
        $MouseCoord = MouseGetPos()
        $X = $MouseCoord[0]
        $Y = $MouseCoord[1]
    EndIf
    
    ;MsgBox(0,"",$x & ' x ' & $y & @crlf & $Clicks & @crlf & $sButton)

    For $i = 1 To $Clicks
        DllCall("user32.dll", "int", "SendMessage", "hwnd", $hwnd, "int", $WM_MOUSEMOVE, "int", 0, "long", _MakeLong($X, $Y))
        DllCall("user32.dll", "int", "SendMessage", "hwnd", $hwnd, "int", $ButtonDown, "int", $Button, "long", _MakeLong($X, $Y))
        DllCall("user32.dll", "int", "SendMessage", "hwnd", $hwnd, "int", $ButtonUp, "int", $Button, "long", _MakeLong($X, $Y))
    Next
EndFunc  ;==>_MouseClickPlus


Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc  ;==>_MakeLong

The reply values are not the same as when I press the buttons manually (these change between different clicks ?), but at least there ARE replies registered.

Best Regards

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  

×