Jump to content
Sign in to follow this  
foxnbk

Simple Script with HotKeySet doesn't work

Recommended Posts

foxnbk

Hi,

i just "coded" a simple script, including HotKeySet... but it doesn't work. It's closing itself after i started it without any message or error.

Here is the script:

HotKeySet("{F4}", "StartProg") 
Func StartProg()
    Sleep (100)
    MouseClick ("left", 569, 728)
    Sleep (100)
    MouseClick ("left", 607, 732)
    Sleep (100)
    MouseClick ("left", 469, 658)
    Sleep (100)
EndFunc

I just want the Script to make 3 clicks at different points, but just after i pressed a Hotkey (For example "F4"). I am a newbie on AutoIT... Can someone help me?

PS: "SyntaxCheck Prod" says, that there's no problem with the syntax' (or something like this :D).

Share this post


Link to post
Share on other sites
Melba23

foxnbk,

Your script exits becasue you have not told it to do anything else! As soon as it sets the HotKey, it finishes.

Try this instead:

HotKeySet("{F4}", "StartProg") 
HotKeySet("{ESC}", "EndProg")

; Infinite loop
While 1
Sleep(100)
WEnd

Func StartProg()
    Sleep (100)
    MouseClick ("left", 569, 728)
    Sleep (100)
    MouseClick ("left", 607, 732)
    Sleep (100)
    MouseClick ("left", 469, 658)
    Sleep (100)
EndFunc

Func EndProg()
    Exit
EndFunc

This way your script keeps running until you stop it with the ESC key.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
YellowLab

The behavior is as you set it - you set the hot key, then your program exits. If you want the hot key to remain active, you need to keep the script active. For instance, keeping the script active while a certain process exists (While ProcessExists) or just globally keeping the script active (While 1). Look into control loops in the help file.

Bob


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites
Monamo

Hi,

i just "coded" a simple script, including HotKeySet... but it doesn't work. It's closing itself after i started it without any message or error.

Here is the script:

HotKeySet("{F4}", "StartProg") 
Func StartProg()
    Sleep (100)
    MouseClick ("left", 569, 728)
    Sleep (100)
    MouseClick ("left", 607, 732)
    Sleep (100)
    MouseClick ("left", 469, 658)
    Sleep (100)
EndFunc

I just want the Script to make 3 clicks at different points, but just after i pressed a Hotkey (For example "F4"). I am a newbie on AutoIT... Can someone help me?

PS: "SyntaxCheck Prod" says, that there's no problem with the syntax' (or something like this :D).

Based on your wording, I assume this is the full content of your script. If that's the case, then basically what you need to do is to include some form of loop to keep the script active while it's waiting for input (in the form of your hotkey).

Give this a shot (press ESC to exit the script):

HotKeySet("{F4}", "StartProg")
HotKeySet("{ESC}","_ExitIt")

While 1
    Sleep(10)
Wend

Func _ExitIt()
    Exit()
EndFunc

Func StartProg()
    Sleep (100)
    MouseClick ("left", 569, 728)
    Sleep (100)
    MouseClick ("left", 607, 732)
    Sleep (100)
    MouseClick ("left", 469, 658)
    Sleep (100)
EndFunc

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites
foxnbk

Hm, it does work now. Thank you all alot, it was very helpfull :D

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.