mr-es335 Posted Wednesday at 05:44 PM Posted Wednesday at 05:44 PM (edited) Good day, I require a means of responding to the selection of the [Enter] key - wherein a MouseClick operation is then executed. I have the following sampling and am wondering if there might be: a) a more "elegant" means of executing this operation ...or... b) a more "simplified" means of executing this operation... Here is the sampling... ; ----------------------------------------------------------- #include <AutoItConstants.au3> #include <Misc.au3> ; ----------------------------------------------------------- GetKeyPress() ; ----------------------------------------------------------- Func GetKeyPress() Local $hDLL = DllOpen("user32.dll") ; ----------------------------------------------------------- While 1 If _IsPressed("0D", $hDLL) Then While _IsPressed("0D", $hDLL) Sleep(250) WEnd MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) ExitLoop EndIf Sleep(250) WEnd ; ----------------------------------------------------------- DllClose($hDLL) EndFunc ;==>GetKeyPress ; ----------------------------------------------------------- As always...any assistance in this matter would be greatly appreciated! Thank you all for your time! Edited Wednesday at 10:32 PM by mr-es335 typo mr-es335 Sentinel Music Studios
Werty Posted Wednesday at 08:07 PM Posted Wednesday at 08:07 PM You pretty much got what we are allowed to discuss on that subject, going deeper would be against forum rules as it's not allowed to discuss keylogging or keypresses other than a few simple _IsPressed() which you already got. Some guy's script + some other guy's script = my script!
argumentum Posted Wednesday at 08:39 PM Posted Wednesday at 08:39 PM 2 hours ago, mr-es335 said: I require a means of responding to the selection selecting of the [Enter] key expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("Custom MsgBox", 225, 80) GUICtrlCreateLabel("Please select a button.", 10, 10) Local $idButton_Yes = GUICtrlCreateButton("Yes", 10, 50, 65, 25) Local $idButton_No = GUICtrlCreateButton("No", 80, 50, 65, 25) Local $idButton_Exit = GUICtrlCreateButton("Exit", 150, 50, 65, 25) ; Set GUIAccelerators for the button controlIDs, these being Ctrl + y and Ctrl + n Local $aAccelKeys[2][2] = [["^y", $idButton_Yes], ["^n", $idButton_No]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) ; Display the GUI. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE MsgBox($MB_SYSTEMMODAL, "You selected", "Close") ExitLoop Case $idButton_Yes MsgBox($MB_SYSTEMMODAL, "You selected", "Yes") ; Displays if the button was selected or the hotkey combination Ctrl + y was pressed. Case $idButton_No MsgBox($MB_SYSTEMMODAL, "You selected", "No") ; Displays if the button was selected or the hotkey combination Ctrl + n was pressed. Case $idButton_Exit MsgBox($MB_SYSTEMMODAL, "You selected", "Exit") ExitLoop EndSwitch WEnd GUIDelete() ; Delete the GUI. EndFunc ;==>Example ..is in the help file. mr-es335 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ioa747 Posted Wednesday at 09:26 PM Posted Wednesday at 09:26 PM (edited) #include <AutoItConstants.au3> HotKeySet("{ENTER}", "MouseClickAction") While 1 Sleep(100) WEnd Func MouseClickAction() HotKeySet("{ENTER}") MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) Sleep(100) HotKeySet("{ENTER}", "MouseClickAction") EndFunc If you want to leave after clicking #include <AutoItConstants.au3> HotKeySet("{ENTER}", "MouseClickAction") Global $bActive = True While $bActive Sleep(100) WEnd Func MouseClickAction() HotKeySet("{ENTER}") MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) $bActive = False EndFunc Edited Wednesday at 09:44 PM by ioa747 mr-es335 1 I know that I know nothing
mr-es335 Posted Wednesday at 11:11 PM Author Posted Wednesday at 11:11 PM (edited) Good day... May I ask how to "integrate" your2nd offering "If you want to leave after clicking" into the following?: ; ----------------------------------------------- #include <AutoItConstants.au3> ; ----------------------------------------------- Global $iTimeOut = 100 Global $iX = 711, $iY = 80 ; For F12 ; ----------------------------------------------- UpdateScenesF12($iX, $iY) ; ----------------------------------------------- Func UpdateScenesF12($iX, $iY) ConsoleWrite("UpdateScenes(" & $iX & ", " & $iY & ")" & @CRLF) Local $hSAC_MAIN = "[CLASS:SAC_MAIN]" Local $hSAC_SCENES = "[CLASS:SAC_SCENES]" Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]" ; ----------------------------------------------- WinActivate($hSAC_MAIN) WinActivate($hSAC_SCENES) ; ----------------------------------------------- ; <<<<==== Script Intervention ====>>>> Send("{End}") ; Select [End Of List] ; ----------------------------------------------- Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0) ; Select [New], the [Enter Scene Name] dialog is displayed. ; ----------------------------------------------- Send("{CTRLDOWN}") Send("v") ; Enter Scene Name Send("{CTRLUP}") ; ---------------------- Send("{ENTER}") ; Select [Ok], the [Enter Scene Name] dialog is exited...and the [Scene Properties] dialog is displayed ; ----------------------------------------------- Sleep($iTimeOut) WinMove($hSAC_SCENEPROPERTIES, "", $iX, $iY) ; The [Scene Properties] dialog is repositioned ; ----------------------------------------------- Sleep($iTimeOut) MouseMove(1000, 550, 0) ; The mouse is positioned within the [Scene Properties] dialog EndFunc ;==>UpdateScenesF12 ; ----------------------------------------------- ...this is point where the [Enter] key is invoked and the MouseClick occurs... PS: I have been able to do so, with my offering, but NOT with the 2nd offering!?!... Edited Wednesday at 11:13 PM by mr-es335 mr-es335 Sentinel Music Studios
ioa747 Posted yesterday at 12:06 AM Posted yesterday at 12:06 AM You don't seem to call GetKeyPress anywhere How do I understand at what point you want it? Why don't you just put MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) and do it with enter? I know that I know nothing
Trong Posted yesterday at 06:18 AM Posted yesterday at 06:18 AM You may not need to use _IsPressed(): expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; === Create GUI === Global $hGUI = GUICreate("Demo GUI - Handle Enter (WM_COMMAND)", 400, 200) Global $lblName = GUICtrlCreateLabel("Enter your name:", 30, 30, 150, 20) Global $inpName = GUICtrlCreateInput("", 180, 28, 150, 20) Global $btnOK = GUICtrlCreateButton("OK", 50, 100, 80, 30) Global $btnCancel = GUICtrlCreateButton("Cancel", 160, 100, 80, 30) Global $btnAbout = GUICtrlCreateButton("About", 270, 100, 80, 30) GUISetState(@SW_SHOW, $hGUI) ; === Register Windows message handler for WM_COMMAND === GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; === Main loop === While True Local $nMsg = GUIGetMsg() Switch $nMsg ;~ Case $btnOK ;This is not necessary! ;~ Action_OK() ;~ Case $btnCancel;This is not necessary! ;~ Action_Cancel() ;~ Case $btnAbout;This is not necessary! ;~ Action_About() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) Exit ; ========================================================= ; === WM_COMMAND message handler === ; ========================================================= Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Local $nCtrlID = BitAND($wParam, 0xFFFF) Local $nCode = BitShift($wParam, 16) ; Handle Enter key press (BN_CLICKED / EN_CHANGE etc.) If $nCode = 0 Then Switch $nCtrlID Case $inpName Action_Input() Case $btnOK Action_OK() Case $btnCancel Action_Cancel() Case $btnAbout Action_About() EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ; ========================================================= ; === Action Functions === ; ========================================================= Func Action_Input() Local $sText = StringStripWS(GUICtrlRead($inpName), 3) If $sText = "" Then MsgBox($MB_ICONWARNING, "Warning", "Please enter your name!") GUICtrlSetState($inpName, $GUI_FOCUS) Return EndIf MsgBox($MB_ICONINFORMATION, "Hello", "Hello, " & $sText & "!") EndFunc Func Action_OK() MsgBox($MB_ICONINFORMATION, "OK", "You pressed the OK button or hit Enter on it.") EndFunc Func Action_Cancel() MsgBox($MB_ICONINFORMATION, "Cancel", "You pressed the Cancel button or hit Enter on it.") EndFunc Func Action_About() MsgBox($MB_ICONINFORMATION, "About", "Demo GUI AutoIt") EndFunc Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal
mr-es335 Posted yesterday at 12:39 PM Author Posted yesterday at 12:39 PM (edited) ioa747, 13 hours ago, ioa747 said: You don't seem to call GetKeyPress anywhere How do I understand at what point you want it? Why don't you just put MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) and do it with enter? My apologies, GetKeyPress does not appear work... ; ----------------------------------------------- #include <AutoItConstants.au3> ; ----------------------------------------------- Global $iTimeOut = 100 Global $iX = 711, $iY = 80 ; For F12 ; ----------------------------------------------- UpdateScenesF12($iX, $iY) ; ----------------------------------------------- Func UpdateScenesF12($iX, $iY) ; Various script stuff ; ----------------------------------------------- ; When [ENTER] is selected [for the [OK] button] then ; MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) ; Exit script EndFunc ;==>UpdateScenesF12 ; ----------------------------------------------- Edited yesterday at 01:46 PM by mr-es335 mr-es335 Sentinel Music Studios
Solution ioa747 Posted yesterday at 04:26 PM Solution Posted yesterday at 04:26 PM (edited) my question is why don't you do it like that? (Unless you want it to wait for you to press enter manually) expandcollapse popup; ----------------------------------------------- #include <AutoItConstants.au3> ; ----------------------------------------------- Global $iTimeOut = 100 Global $iX = 711, $iY = 80 ; For F12 ; ----------------------------------------------- UpdateScenesF12($iX, $iY) ; ----------------------------------------------- Func UpdateScenesF12($iX, $iY) ConsoleWrite("UpdateScenes(" & $iX & ", " & $iY & ")" & @CRLF) Local $hSAC_MAIN = "[CLASS:SAC_MAIN]" Local $hSAC_SCENES = "[CLASS:SAC_SCENES]" Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]" ; ----------------------------------------------- WinActivate($hSAC_MAIN) WinActivate($hSAC_SCENES) ; ----------------------------------------------- ; <<<<==== Script Intervention ====>>>> Send("{End}") ; Select [End Of List] ; ----------------------------------------------- Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0) ; Select [New], the [Enter Scene Name] dialog is displayed. ; ----------------------------------------------- Send("{CTRLDOWN}") Send("v") ; Enter Scene Name Send("{CTRLUP}") ; ---------------------- ;~ Send("{ENTER}") ; Select [Ok], the [Enter Scene Name] dialog is exited...and the [Scene Properties] dialog is displayed Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) ; Perform mouse click ⚠️ ; ----------------------------------------------- Sleep($iTimeOut) WinMove($hSAC_SCENEPROPERTIES, "", $iX, $iY) ; The [Scene Properties] dialog is repositioned ; ----------------------------------------------- Sleep($iTimeOut) MouseMove(1000, 550, 0) ; The mouse is positioned within the [Scene Properties] dialog EndFunc ;==>UpdateScenesF12 ; ----------------------------------------------- Edit: ; ----------------------------------------------- #include <AutoItConstants.au3> ; ----------------------------------------------- Global $iTimeOut = 100 Global $iX = 711, $iY = 80 ; For F12 ; Set the hotkey for [Enter] to trigger MouseClickAction HotKeySet("{ENTER}", "MouseClickAction") ; ----------------------------------------------- UpdateScenesF12($iX, $iY) ; ----------------------------------------------- Func UpdateScenesF12($iX, $iY) ; Various script stuff ; ----------------------------------------------- ; When [ENTER] is selected [for the [OK] button] then ; Wait for [Enter] to be pressed and handled by MouseClickAction While $bActive Sleep(100) ; Keeps the loop alive, waiting for the [Enter] hotkey action WEnd MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) Exit script EndFunc ;==>UpdateScenesF12 ; ----------------------------------------------- Func MouseClickAction() HotKeySet("{ENTER}") ; Disable hotkey to prevent repeated clicks ;~ Send("{ENTER}") ; if you want to deliver the Enter key too MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) ; Perform mouse click $bActive = False ; Exit loop in UpdateScenesF12 EndFunc Or alternately ; ----------------------------------------------- #include <AutoItConstants.au3> ; ----------------------------------------------- Global $iTimeOut = 100 Global $iX = 711, $iY = 80 ; For F12 ; ----------------------------------------------- UpdateScenesF12($iX, $iY) ; ----------------------------------------------- Func UpdateScenesF12($iX, $iY) ; Various script stuff ; ----------------------------------------------- ; When [ENTER] is selected [for the [OK] button] then WinWaitClose("the window that closes the ok") MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) Exit script EndFunc ;==>UpdateScenesF12 ; ----------------------------------------------- Edited yesterday at 04:50 PM by ioa747 mr-es335 1 I know that I know nothing
mr-es335 Posted yesterday at 06:22 PM Author Posted yesterday at 06:22 PM (edited) Hello, PS: I thought that I had submitted this earlier...but it never was not submitted....!!! • iso747, I will look at your recent offerings...thanks...as always!! Is the following "DO"-able?? expandcollapse popup; ----------------------------------------------- #include <AutoItConstants.au3> #include <misc.au3> ; ----------------------------------------------- Global $iTimeOut = 100 Global $iX = 711, $iY = 80 ; For F12 ; ----------------------------------------------- UpdateScenesF12($iX, $iY) ; ----------------------------------------------- Func UpdateScenesF12($iX, $iY) ConsoleWrite("UpdateScenes(" & $iX & ", " & $iY & ")" & @CRLF) Local $hSAC_MAIN = "[CLASS:SAC_MAIN]" Local $hSAC_SCENES = "[CLASS:SAC_SCENES]" Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]" ; ----------------------------------------------- WinActivate($hSAC_MAIN) WinActivate($hSAC_SCENES) ; ----------------------------------------------- ; <<<<==== Script Intervention ====>>>> Send("{End}") ; Select [End Of List] ; ----------------------------------------------- Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0) ; Select [New], the [Enter Scene Name] dialog is displayed. ; ----------------------------------------------- Send("{CTRLDOWN}") Send("v") ; Enter Scene Name Send("{CTRLUP}") ; ---------------------- Send("{ENTER}") ; Select [Ok], the [Enter Scene Name] dialog is exited ; ...and the [Scene Properties] dialog is displayed ; ----------------------------------------------- Sleep($iTimeOut) WinMove($hSAC_SCENEPROPERTIES, "", $iX, $iY) ; The [Scene Properties] dialog is repositioned ; ----------------------------------------------- Sleep($iTimeOut) MouseMove(1000, 550, 0) ; The mouse is positioned within the [Scene Properties] dialog ; ----------------------------------------------- Do Sleep(1) Until _IsPressed("0D") ; ----------------------------------------------- Sleep($iTimeOut) MouseClick($MOUSE_CLICK_LEFT, 134, 163, 2, 0) EndFunc ;==>UpdateScenesF12 ; ----------------------------------------------- Edited yesterday at 06:24 PM by mr-es335 mr-es335 Sentinel Music Studios
ioa747 Posted yesterday at 06:33 PM Posted yesterday at 06:33 PM (edited) yes it is "DO"-able?? (and the simplest) the only dissonance is Sleep(1) the smallest possible is Sleep(10) Maximum sleep time is 2147483647 milliseconds (24 days) and the minimum is 10 milliseconds. So using 1-9 will automatically default to 10 milliseconds. Edited yesterday at 06:43 PM by ioa747 I know that I know nothing
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