autoitter Posted April 24, 2020 Posted April 24, 2020 Hi, I'm writing a piece of software that controls a PTZ camera. One of the things I'm trying to achieve is that the camera moves while the users keeps a button pressed in the GUI. Movement should stop as soon as the user releases the button. I can check if the mouse key is pressed with the _IsPressed() function. But the GuiCtrlSetOnEvent function only gets called when the button is released. Is there any way to get an event as soon as the button is pressed down? Best regards
MrCreatoR Posted April 24, 2020 Posted April 24, 2020 8 minutes ago, autoitter said: Is there any way to get an event as soon as the button is pressed down? Yes: #include <GUIConstantsEx.au3> #include <WinAPISysWin.au3> #include <WinAPIMisc.au3> $hGUI = GUICreate('Test Script', 300, 200) $iButton = GUICtrlCreateButton('Button', 20, 40, 60, 20) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $tPont = _WinAPI_GetMousePos() Switch _WinAPI_WindowFromPoint($tPont) Case GUICtrlGetHandle($iButton) _Bttn_Event() EndSwitch EndSwitch WEnd Func _Bttn_Event() ConsoleWrite('Primary down' & @CRLF) EndFunc Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
MrCreatoR Posted April 24, 2020 Posted April 24, 2020 (edited) Or change the button: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPISysWin.au3> #include <WinAPIMisc.au3> Opt('GUIOnEventMode', 1) $hGUI = GUICreate('Test Script', 300, 200) $iButton = _Button('Button', 20, 40, 70, 22) GUICtrlSetOnEvent($iButton, '_Events') GUISetOnEvent($GUI_EVENT_CLOSE, '_Events', $hGUI) GUISetOnEvent($GUI_EVENT_PRIMARYUP, '_Events', $hGUI) GUISetState(@SW_SHOW, $hGUI) While 1 Sleep(10) WEnd Func _Button($sText, $iL, $iT, $iW, $iH) Local $iID = GUICtrlCreateLabel($sText, $iL, $iT, $iW, $iH, BitOR($SS_CENTER, $SS_CENTERIMAGE), $WS_EX_DLGMODALFRAME) Return $iID EndFunc Func _Events() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYUP GUICtrlSetStyle($iButton, -1, $WS_EX_DLGMODALFRAME) ConsoleWrite('Primary up' & @CRLF) Case $iButton GUICtrlSetStyle($iButton, -1, $WS_EX_CLIENTEDGE) ConsoleWrite('Primary down' & @CRLF) EndSwitch EndFunc Edited April 24, 2020 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
autoitter Posted April 24, 2020 Author Posted April 24, 2020 Hi MrCreatoR, I used your first suggestion. I use OnEvent mode in my script, but it was easy to convert. Thanks for pointing me in the right direction! Best regards
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