Jump to content

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:

Link to post
Share on other sites
  • Developers

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.
  :)

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
Link to post
Share on other sites
  • Developers

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.
  :)

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

Link to post
Share on other sites
  • Developers

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.
  :)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...