Jump to content
Sign in to follow this  
Guest Execute_Me

Function / Hotkey Question

Recommended Posts

Guest Execute_Me

Hi Dudes,

i have a Question about Hotkeys.

$count = 8
HotKeySet("{F2}", "MousePos")
While $count < 10
$count = $count + 1
Func MousePos()
$file = FileOpen("pos.txt",1)
$pos = MouseGetPos ( )
FileWrite($file,$pos[0] & "," & $pos[1] & @CRLF)
EndFunc
WEnd

FileClose ($file)

This is my little, buggy Script.

It doesnt work and i don't know why .. but the main question is ->

Is this the right way to use hotkeys?

I wanted to make a proggy which saves the Mouse Positions every time a use a hotkey into a .txt File.

But i have some problems with holding a window opened to end this.

Means -> The Window stays open all the time and ín this time i can make some mousecoords.

:idiot:

Share this post


Link to post
Share on other sites

Func statement cannot be inside a loop.

Below script will loop forever and anytime you hit F2 will write the mouse pos at the end of the file :

Global $file = "pos.txt"
HotKeySet("{F2}", "MousePos")
While 1
    sleep(10)
WEnd
;
Func MousePos()
    $pos = MouseGetPos()
    FileWriteLine($file, $pos[0] & "," & $pos[1])
EndFunc  ;==>MousePos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest Execute_Me

Why you did the Func behind the While .. The Func get invoked before its defined ?

Anf why Sleep (10) ?

The Scripts works well but i don't understand it really :idiot:

Edited by Execute_Me

Share this post


Link to post
Share on other sites

While 1
    sleep(10)
WEnd
That While-WEnd loop keeps the script going, the sleep save your CPU working too hard. While this loop is running, your hotkey F2 is always active to call MousePos() function.

Share this post


Link to post
Share on other sites

Why you did the Func behind the While .. The Func get invoked before its defined ?

Anf why Sleep (10) ?

The Scripts works well but i don't understand it really  :idiot:

<{POST_SNAPBACK}>

Just read up on Functions in the helpfile or the online manual

See if that explains it for you.... :D


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest Execute_Me

ahh yeah .... every 10 seconds is writes the koords ! :idiot:

; bla

Global $file = "pos.txt"
HotKeySet("{F2}", "MousePos")
HotKeySet("{F3}", "End")
While 1
    sleep(10)
WEnd
;
Func MousePos()
    $pos = MouseGetPos()
    FileWriteLine($file, $pos[0] & "," & $pos[1])
EndFunc ;==>MousePos
Func End()
    Exit
EndFunc;==> End

With Exit Func.... but i didn't get a Window Work .. if i click on the "OK" button it stops the Script.

Somebody could tell me how? something like If MsgBox(0, "bla", "bla") = 1

Then Exit

Share this post


Link to post
Share on other sites

ahh yeah .... every 10 seconds is writes the koords ! :idiot:

<{POST_SNAPBACK}>

Sleep(10) means sleep 10 msec = .01 sec

With Exit Func.... but i didn't get a Window Work .. if i click on the "OK" button it stops the Script.

Somebody could tell me how? something like If MsgBox(0, "bla", "bla") = 1 

Then Exit

<{POST_SNAPBACK}>

You are talking in riddles here ......Do you main you want to get a prompt when you press F3 ????

Like:

Func End()
    If MsgBox(4,"Cancel Execution?","Do you want to cancel the Program?") = 6 Then Exit
EndFunc;==> End

EDIT: corrected calculation... tnx slimshady

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@JdeB and others:

1000 milliseconds =  1 second
100  milliseconds =   0.1 second
10   milliseconds =  0.01 second
1   millisecond  = 0.001 second
Edited by SlimShady

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...