fs1234 Posted April 4, 2019 Posted April 4, 2019 Hi All, I tried this code, but not working: expandcollapse popup#include <Misc.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> Global $DLLUser32 = DllOpen("user32.dll"), $fRun Local $ButtonNo $gui = GUICreate("Test Button Pressed", 350, 250, -1, -1) $Button1 = GUICtrlCreateButton("Button1", 20, 40, 80, 80, $BS_BITMAP) GUICtrlSetImage($Button1, @ScriptDir & "\Button1.bmp") $Button2 = GUICtrlCreateButton("Button2", 120, 40, 80, 80, $BS_BITMAP) GUICtrlSetImage($Button2, @ScriptDir & "\Button2.bmp") $Button3 = GUICtrlCreateButton("Button3", 220, 40, 80, 80, $BS_BITMAP) GUICtrlSetImage($Button3, @ScriptDir & "\Button3.bmp") GUISetState() While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Exit Case $MSG = $Button1 $ButtonNo = "1" _Display() While 1 If _IsPressed("01", $DLLUser32) Then If $fRun Then GUICtrlSetImage($Button1, @ScriptDir & "\Button1_p.bmp") $fRun = False EndIf Else GUICtrlSetImage($Button1, @ScriptDir & "\Button1.bmp") $fRun = True EndIf WEnd Case $MSG = $Button2 $ButtonNo = "2" _Display() While 1 If _IsPressed("01", $DLLUser32) Then If $fRun Then GUICtrlSetImage($Button2, @ScriptDir & "\Button2_p.bmp") $fRun = False EndIf Else GUICtrlSetImage($Button2, @ScriptDir & "\Button2.bmp") $fRun = True EndIf WEnd Case $MSG = $Button3 $ButtonNo = "3" _Display() While 1 If _IsPressed("01", $DLLUser32) Then If $fRun Then GUICtrlSetImage($Button3, @ScriptDir & "\Button3_p.bmp") $fRun = False EndIf Else GUICtrlSetImage($Button3, @ScriptDir & "\Button3.bmp") $fRun = True EndIf WEnd EndSelect WEnd Func _Display() MsgBox(0, "", $ButtonNo) EndFunc The first pressed button changes continuously. Help, pls. Button1.bmp Button1_p.bmp Button2.bmp Button2_p.bmp Button3.bmp Button3_p.bmp
Nine Posted April 5, 2019 Posted April 5, 2019 I think the best way is to use callback, like this : expandcollapse popup#include <Constants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPIConstants.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Local $gui = GUICreate("Test Button Pressed", 350, 250, -1, -1) Local $Button1 = GUICtrlCreateButton("Button1", 20, 40, 80, 80, $BS_BITMAP) GUICtrlSetImage($Button1, @ScriptDir & "\Button1.bmp") Local $Button2 = GUICtrlCreateButton("Button2", 120, 40, 80, 80, $BS_BITMAP) GUICtrlSetImage($Button2, @ScriptDir & "\Button2.bmp") Local $Button3 = GUICtrlCreateButton("Button3", 220, 40, 80, 80, $BS_BITMAP) GUICtrlSetImage($Button3, @ScriptDir & "\Button3.bmp") GUISetState() Local $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") Local $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Button1), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) _WinAPI_SetWindowLong(GUICtrlGetHandle($Button2), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) _WinAPI_SetWindowLong(GUICtrlGetHandle($Button3), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 ConsoleWrite("button 1 pushed" & @CRLF) EndSwitch WEnd GUIDelete($gui) DllCallbackFree($wProcHandle) Func _WindowProc($hWnd, $iMsg, $wParam, $lParam) Switch $hWnd Case GUICtrlGetHandle($Button1) Switch $iMsg Case $WM_LBUTTONDOWN ConsoleWrite("Left mouse down" & @CRLF) GUICtrlSetImage($Button1, @ScriptDir & "\Button1_p.bmp") Case $WM_LBUTTONUP ConsoleWrite("Left mouse up" & @CRLF) GUICtrlSetImage($Button1, @ScriptDir & "\Button1.bmp") Case $WM_KEYDOWN If $wParam = 32 Then ConsoleWrite("Key Down " & $wParam & @CRLF) GUICtrlSetImage($Button1, @ScriptDir & "\Button1_p.bmp") EndIf Case $WM_KEYUP If $wParam = 32 Then ConsoleWrite("Key Up " & $wParam & @CRLF) GUICtrlSetImage($Button1, @ScriptDir & "\Button1.bmp") EndIf EndSwitch EndSwitch Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WindowProc _WindowProc manages only button 1. But you can complete it by yourself. I also added the key press “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
fs1234 Posted April 5, 2019 Author Posted April 5, 2019 Thanks Nine, When I run the script I got an error: test2.au3 (9) : ==> Unable to parse line.: ? ^ ERROR Whats wrong?
Nine Posted April 5, 2019 Posted April 5, 2019 must be a bad characters coming from copy/paste, just delete it. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
fs1234 Posted April 5, 2019 Author Posted April 5, 2019 (edited) Damn it! Of course... Work perfectly. Thanks! Edited April 5, 2019 by fs1234
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now