Jump to content

[Solved] The Best way to detect middle mouse button?


Madza91
 Share

Recommended Posts

Hello!

I best way to detect when is middle mouse pushed...

I know for Mouse Hook without any external dll files, but it is bugged, and I posted that bug on this topic...

...Now, how I can detect middle mouse without any external dll files, and without any bags? :)

Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

Clicking might work with:

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep ( 250 )
    If _IsPressed("04", $dll) Then
        MsgBox(0,"_IsPressed", "End Key Pressed")
        ExitLoop
    EndIf
WEnd
DllClose($dll)
Link to comment
Share on other sites

I know for that... It is very slow way... Because i have in While many things, and that is not very smart... Better will be over some notify func...

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

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

Global Const $WM_MBUTTONDOWN = 0x0207

Local $msg

GUICreate("My GUI"); will create a dialog box that when displayed is centered
GUISetState(@SW_SHOW); will display an empty dialog box
GUIRegisterMsg($WM_MBUTTONDOWN, "MY_WM_MBUTTONDOWN")

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Func MY_WM_MBUTTONDOWN($hWnd, $iMsg, $iwParam, $ilParam)
    ConsoleWrite('Click')
EndFunc  ;==>MY_WM_MBUTTONDOWN

Link to comment
Share on other sites

Hah... I forget to tell you, I know for this too, but this is bugged when add some controls, for example, create Edit or Input, and Focus it, and when is Mouse over that Edit or Input your solution wont work...

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

I founded better way - Window Proc... :lmao:

If someone know better way, pls post it, but i think this is perfect! Hehehe :)

Here is code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <GuiTab.au3>

Opt('MustDeclareVars', 1)

Global $ContextMenu, $CommonMenuItem, $FileMenuItem, $ExitMenuItem
Global $hGui, $cInput, $wProcOld
Global Const $WM_MBUTTONUP = 0x0208

_Main()

Func _Main()
    Local $cInput2, $wProcNew, $DummyMenu, $cTab
    
    $hGui = GUICreate("Type or paste some stuff", 400, 200, -1, -1, $WS_THICKFRAME, -1)
;~  $cTab = GUICtrlCreateTab(10, 10, 350, 150)
    $cTab = _GUICtrlTab_Create($hGui, 10, 10, 350, 150)
    _GUICtrlTab_InsertItem($cTab, 0, "Some text...")
    GUICtrlCreateTabItem("Click here with Middle Mouse Button")

    $wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
    $wProcOld = _WinAPI_SetWindowLong($cTab, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))

    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_Main

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_MBUTTONUP
            MsgBox(0,"","As you can see Middle Mouse Button works... ;P")
    EndSwitch
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc
Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

Hmmm, doesn't work for me :)

Edit: Oh, I see, you have to click on the tab-header...

But e.g. edit-controls still consum the clicks (have no middle mouse-button on my notebook, thus I changed to left :lmao: )...

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

Opt('MustDeclareVars', 1)

Global $hGui, $wProcOld
Global Const $WM_LBUTTONDOWN = 0x0201

_Main()

Func _Main()
    Local $wProcNew
    
    $hGui = GUICreate("Left Click", 400, 200, -1, -1, $WS_THICKFRAME, -1)
    
    GUICtrlCreateEdit("",40,40,200,110)

    $wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
    $wProcOld = _WinAPI_SetWindowLong($hGui, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))

    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_Main

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_LBUTTONDOWN
            MsgBox(0,"","Left Mouse Button")
    EndSwitch
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc
Edited by KaFu
Link to comment
Share on other sites

KaFu, you want to detect it on Edit ?

Edit: When create Edit with GUICtrlCreateEdit, you need to get handle of it when using Func _WinAPI_SetWindowLong...

Try this:

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

Opt('MustDeclareVars', 1)

Global $hGui, $cInput, $wProcOld
Global Const $WM_LBUTTONDOWN = 0x0201

_Main()

Func _Main()
    Local $wProcNew, $edit
   
    $hGui = GUICreate("Left Click", 400, 200, -1, -1)
   
    $cInput = GUICtrlCreateEdit("",40,40,200,110)

    $wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
    $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($cInput), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))

    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_Main

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_LBUTTONDOWN
            MsgBox(0,"","Left Mouse Button")
            Return 0;and don't let default windowproc mess things up
    EndSwitch
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc
Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

KaFu, you want to detect it on Edit ?

Eh... you wanted it, said so in reply to my GUIRegisterMsg() sugesstion.

Hah... I forget to tell you, I know for this too, but this is bugged when add some controls, for example, create Edit or Input, and Focus it, and when is Mouse over that Edit or Input your solution wont work...

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