Jump to content

Recommended Posts

Posted (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 by mr-es335
typo
Posted

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!

Posted
2 hours ago, mr-es335 said:

I require a means of responding to the selection selecting of the [Enter] key

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

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

:unsure:

#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 by ioa747

I know that I know nothing

Posted (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 by mr-es335
Posted

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

Posted

You may not need to use _IsPressed():

#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

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
  • Recently Browsing   1 member

×
×
  • Create New...