Jump to content

Hotkey Input .. Fail?


Recommended Posts

Hey, so i started Learning AutoIt yesterday.. and after reading, testing (Lots of infinte {Tab} Loops :)) I figured that i need help, because this stuff still is somewhat out of my Leauge

So the idea is that the Script should check if the Application is Running, If not, Exit -

(That part works 50%, but does not Exit when i quit the Application after i launch the Script - Not the Main Issue though)

And Do the Function every time i press "W"

HotKeySet("{w}", "Poof")
MsgBox(0,"Running","Running")           ;MessageBox Informing that the Script is Running
WinActivate("Application")            ;Changes to the "Application"   Window
WinActive("Application")            ; Runs Until "Aplication" is Closed
While WinActive("Application")
Sleep (100)
WEnd
Func Poof()                 ;When User Presses  W   Do:

Send("{w}")
MouseClick("left")
Send("{tab}")
Sleep(1)
Send("{w}")
MouseClick("left")
Send("{tab}")
Sleep(1)
Send("{w}")
MouseClick("left")
Send("{tab}")
Sleep(1)
Send("{w}")
MouseClick("left")
Send("{tab}")

EndFunc
MsgBox(0,"Not Running","Not Running")   ; Informs that the "Application" is no longer Running

When i launch the script, i can't even Use the W key while the Script is Running.

I have also tried IF THEN Statements:

Func Poof()
        If  StringInStr("{w}","{w}") Then
And
Func Poof()
        If  StringInStr("@HotKeyPressed","{w}") Then

After 1 min or so, the script will exit to prevent overflow: " Recursion level has been exceeded"

Ive looked it up and "That usually means you have a logical loop where a function is calling itself."

While i kinda get it.. (This is pretty much the first time i am programming) I think it means i am building the whole script wrong.

Any idea what i can do so it will do my function every time i press W , and how to prevent the Overflow?

Link to comment
Share on other sites

  • Moderators

Hi, Schoening. To begin with, if you're wanting to use "w" for your hotkey, take out the {}. Ex.:

HotKeySet("w", "Poof")

Func Poof()
MsgBox(0, "", "Bye")
Exit
EndFunc

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

To continue with what JLogan3o13 was staying, change the "{w}" to "w" in your Send as well.

Try this

HotKeySet("w", "Poof")
MsgBox(0,"Running","Running")          ;MessageBox Informing that the Script is Running
WinActivate("Application")          ;Changes to the "Application"   Window
WinActive("Application")            ; Runs Until "Aplication" is Closed
While WinActive("Application")
Sleep (100)
WEnd
Func Poof()              ;When User Presses  W   Do:

Send("w")
MouseClick("left")
Send("{tab}")
Sleep(1)
Send("w")
MouseClick("left")
Send("{tab}")
Sleep(1)
Send("w")
MouseClick("left")
Send("{tab}")
Sleep(1)
Send("w")
MouseClick("left")
Send("{tab}")

EndFunc
MsgBox(0,"Not Running","Not Running")   ; Informs that the "Application" is no longer Running

Adam

Edited by AdamUL
Link to comment
Share on other sites

Thx :) But it is still not doing what i want it to do...

It is still not doing what i want it to do, The Function is Running but is only "Pressing the W Key" in the Application when i Hold down Shift.. And After Some Time .. It Overflows. Also.. the Function is just Looping .. It is supposed to stop after doing the

Send("w") MouseClick("left") Send("{tab}") 4 Times..

This is How the Script Looked Last It didnt run out of memory

MsgBox(0,"Running","Running")           ;MessageBox Informing that the Script is Running
WinActivate("Application")            ;Changes to the "Application"   Window
WinActive("Application")            ; Runs Until "Aplication" is Closed
While WinActive("Application")
  Sleep (5000)

Send("w")
MouseClick("left")
Send("{tab}")
Send("w")
MouseClick("left")
Send("{tab}")
Sleep(1)
Send("w")
MouseClick("left")
Send("{tab}")
Sleep(1)
Send("w")
MouseClick("left")
Send("{tab}")
WEnd

MsgBox(0,"Not Running","Not Running")   ; Informs that the "Application" is no longer Running

But Obviously i cannot Control this... And it will just Loop it every 5 Seconds instead of when i Press a Key

Edited by Schoening
Link to comment
Share on other sites

  • Moderators

Schoening,

You are Sending the same key as you use for the HotKey - so each time you Send it you merely action the HotKey again. :D

Try disabling the HotKey as you enter the function and then re-enabling it as you leave:

HotKeySet("w", "Poof")

MsgBox(0, "Running", "Running") ;MessageBox Informing that the Script is Running

WinActivate("Application") ;Changes to the "Application"   Window
; You need to wait until the window is active or you could never enter the loop below <<<<<<<<<<<<<<<<<<<
WinWaitActive("Application") ; Runs Until "Aplication" is Closed

While WinActive("Application")
    Sleep(100)
WEnd

Func Poof() ;When User Presses  W   Do:

    While WinActive("Application")

        HotKeySet("w") ; Disable HotKey <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        Sleep(5000)

        Send("w")
        MouseClick("left")
        Send("{tab}")
        Send("w")
        MouseClick("left")
        Send("{tab}")
        Sleep(10) ; <<<<<<<<<<<<<<<<<<<<<<<<< What did I tell you about Sleep?
        Send("w")
        MouseClick("left")
        Send("{tab}")
        Sleep(10)
        Send("w")
        MouseClick("left")
        Send("{tab}")

        HotKeySet("w", "Poof") ; Re-enable HotKey <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    WEnd

EndFunc   ;==>Poof

MsgBox(0, "Not Running", "Not Running") ; Informs that the "Application" is no longer Running

I have not tested it because I do not know what the "Application" might be - see it it works for you. ;)

M23

Edit: I see you worked it out yourself - congratulations! :)

Edited by Melba23
Added new text

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Schoening,

You are quite correct. I ended up with a mixture of your various posts and left the While...Wend loop in the function - my apologies. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hi Schoening, since you're using Send commands, you're going to wreak havoc as soon as the focus leaves your application's window anyway. If you're looking to do this in the background, I would suggest looking into the ControlSend options in the Help file.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi Schoening, since you're using Send commands, you're going to wreak havoc as soon as the focus leaves your application's window anyway. If you're looking to do this in the background, I would suggest looking into the ControlSend options in the Help file.

Ok, I will do that Thx :)

I Just found a bigger Problem.. The Whole Script Only Works When the "Application" is in Windowed Mode... Else it just Jumps to

MsgBox(0,"Not Running","Not Running")    ; Informs that the "Application" is no longer Running
Like When I am Not Running the "Application" at all
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...