Jump to content
Sign in to follow this  
Ph03nX

2 functions at the same time

Recommended Posts

Ph03nX

i have 2 keys e.g. 8 and 4 both start a function.

8 sends keys

4 sends mouselicks

seperate they work fine. I click 8 i start sending keys. i click 4, i get mouseclicks. But how can i make both work at the same time. sending keys and mouseclicks!

If i click 8 i cancel 4 , if i click 4 i cancel 8

I think it's cos the first function waits for the 2nd function it's loop to finish. but it wont finish it's infinte, for both functions

Don't tell me to put them together in 1 function cos there's a sleep on the mouseclicks which i dont want when on the text that is send.

Can any1 pleaaaase help? Thanks

Edited by Ph03nX

Share this post


Link to post
Share on other sites
ChrisL

You cant run 2 functions at the same time so you have a couple of choices.

First is to put mouse clicks and keystrokes in the same function, I know you said you didn't want to because of sleeps, but don't use sleeps, user timers.

While 1
$mouseTimer = TimerInit()
$KeyTimer = TimerInit()

If TimerDiff($MouseTimer) >= 2000 then 
MouseClick() etc etc
$mouseTimer = TimerInit()
Endif

If TimerDiff($keyTimer) >= 5000 then
Send() etc etc
$KeyTimer = TimerInit()
Endif
Wend

The second option you have is to write the 2 different functions as 2 different au3 files.

Then have a 3rd au3 script which calles one of the other ones with hotkeys

Func MouseClicker()
Run (@Autoitexe & " /AutoIt3ExecuteScript  Mouseclick.au3")
Endfunc

Edited Idiot error!

Edited by ChrisL

Share this post


Link to post
Share on other sites
martin

i have 2 keys e.g. 8 and 4 both start a function.

8 sends keys

4 sends mouselicks

seperate they work fine. I click 8 i start sending keys. i click 4, i get mouseclicks. But how can i make both work at the same time. sending keys and mouseclicks!

If i click 8 i cancel 4 , if i click 4 i cancel 8

I think it's cos the first function waits for the 2nd function it's loop to finish. but it wont finish it's infinte, for both functions

Don't tell me to put them together in 1 function cos there's a sleep on the mouseclicks which i dont want when on the text that is send.

Can any1 pleaaaase help? Thanks

You might need to do something like this- (my thinking code)

$t8 = timerinit()

$8cycles = 0

$t4 = timerinit()

$4cycles = 0

while 1

if 8 pressed then $8 = true

if 4 pressed then $4 = true

if $8 then

if timerdiff($t8) >= timedelayforkeything then

do keything

$t8 = timerinit()

$8cycles += 1

if $8cycles = enough then $8 = false

end

if $4...etc

same but do clickthing

.

.

wend


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Ph03nX

You cant run 2 functions at the same time so you have a couple of choices.

First is to put mouse clicks and keystrokes in the same function, I know you said you didn't want to because of sleeps, but don't use sleeps, user timers.

While 1
$mouseTimer = TimerInit()
$KeyTimer = TimerInit()

If TimerDiff($MouseTimer) >= 2000 then 
MouseClick() etc etc
$mouseTimer = TimerInit()
Endif

If TimerDiff($keyTimer) >= 5000 then
Send() etc etc
$KeyTimer = TimerInit()
Endif
Wend

The second option you have is to write the 2 different functions as 2 different au3 files.

Then have a 3rd au3 script which calles one of the other ones with hotkeys

Func MouseClicker()
Run (@Autoitexe & " /AutoIt3ExecuteScript  Mouseclick.au3")
Endfunc

Edited Idiot error!

Can that be compiled into 1 .exe, if i'd write each function in a diffrent file?

(thanks for all help so far everyone :) )

Share this post


Link to post
Share on other sites
ChrisL

Can that be compiled into 1 .exe, if i'd write each function in a diffrent file?

(thanks for all help so far everyone :) )

Yes you could fileInstal() the extra scripts, or you could write them out dynamically when it runs.

$string = Msgbox(0,"My Message","Hello") & @crlf & Msgbox(0,"Secondline","Another message box")

FileWrite("C:\mySecondScript.au3",$string)

Run (@Autoitexe & " /AutoIt3ExecuteScript  C:\mySecondScript.au3")

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  

×