Sign in to follow this  
Followers 0
alfonso

Events ButtonPress and ButtonRelease

3 posts in this topic

Is there any easy way to get/simulate events ButtonPress and ButtonRelease?

Thanks in advance,

Alfonso

Share this post


Link to post
Share on other sites



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

Global Const $WM_MOUSEMOVE = 0x0200
Global Const $WM_LBUTTONDOWN = 0x0201
Global Const $WM_LBUTTONUP = 0x0202

Global $hGUI
Global $Button, $hButton
Global $hFunc, $pFunc
Global $hOldProc
Global $fPressed = False

$hFunc = DllCallbackRegister('ButtonProc', 'int', 'hwnd;uint;wparam;lparam')
$pFunc = DllCallbackGetPtr($hFunc)

$hGUI = GUICreate('Test', 100, 100)
$Button = GUICtrlCreateButton('Text', 20, 40, 60, 23)
$hButton = GUICtrlGetHandle(-1)

$hOldProc = _WinAPI_GetWindowLong($hButton, $GWL_WNDPROC)
_WinAPI_SetWindowLong($hButton, $GWL_WNDPROC, $pFunc)

GUISetState()

Do
Until GUIGetMsg() = -3

GUIDelete()
DllCallbackFree($hFunc)
Exit


Func ButtonProc($hwnd, $iMsg, $iwParam, $ilParam)
    Switch $iMsg
        Case $WM_LBUTTONDOWN
            ConsoleWrite('Pressed' & @LF)
            $fPressed = True
        Case $WM_LBUTTONUP
            ConsoleWrite('Release' & @LF)
            $fPressed = False
        Case $WM_MOUSEMOVE
            If $fPressed Then ConsoleWrite('Still pressed' & @LF)
    EndSwitch
    
    Return _WinAPI_CallWindowProc($hOldProc, $hwnd, $iMsg, $iwParam, $ilParam)
EndFunc

Share this post


Link to post
Share on other sites

Thanks Authenticity. It works great!

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