Trying to work Autoit looping

01/26/2011 00:29 Mineraku12#1
Ok this is my first post so im not sure exactly where to put this but heres my script

WinWaitActive("LaTale Client")
#include<misc.au3> ;needed to capture keystrokes
While 1
If _IsPressed("11") And _IsPressed("31") Then;This is what I press to start the loop
Send ("{LCTRL down}")
Sleep(18000); I want it to hold down for 18secs
Send ("{LCTRL up}");I want it to lift off the key
Sleep(8000);and hold for 8secs
EndIf
If _IsPressed("11") And _IsPressed("32") Then
ExitLoop;I use this to exit
EndIf
Wend

When i run the script in my game it holds down the ctrl button, but it does it longer than 18secs and it doesnt lift up afterwards. It just goes until the input key time passes. I would like to know how to use the "UP" function properly and also how to loop it back to where i started to repeat the process.
Thanks
01/26/2011 00:39 theoneofgod#2
Try not use a While 1 loop like that without a sleep, if you notice when you run the above script your CPU can spike between 50/100%

This version should work:

Code:
WinWaitActive("LaTale Client")

While 1
	If _IsPressed("11") And _IsPressed("31") Then
		Send("{CTRLDOWN}")
		Sleep(18000)
		Send("{CTRLUP}")
		Sleep(8000)
	EndIf
	If _IsPressed("11") And _IsPressed("32") Then
		ExitLoop
	EndIf
	Sleep(10)
WEnd

Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
	; $hexKey must be the value of one of the keys.
	; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
	Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
	If @error Then Return SetError(@error, @extended, False)
	Return BitAND($a_R[0], 0x8000) <> 0
EndFunc   ;==>_IsPressed
#Moved to "SRO Coding Corner"
01/26/2011 01:09 Mineraku12#3
Ok thanks now it holds dow for the 18 secs but doesnt loop back to the start and reapeat....also what does this mean
$hexKey must be the value of one of the keys.
; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.

Was i supposed to change some values somewhere?
Should i chang the $hexKey to "31"?


also can u explain this Func? Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
01/26/2011 01:25 theoneofgod#4
The _IsPressed is the function from the Misc UDF, there was no point including the whole include when you use just one of the functions.

Here is another method:

Code:
HotKeySet("^1", "_CtrlDownUp")
HotKeySet("^2", "_Exit")

While 1
	Sleep(10)
WEnd

Func _CtrlDownUp()
	WinWaitActive("LaTale Client")
	While 1
		Send("{CTRLDOWN}")
		Sleep(18000)
		Send("{CTRLUP}")
		Sleep(8000)
	WEnd
EndFunc   ;==>_CtrlDownUp

Func _Exit()
	Exit
EndFunc   ;==>_Exit
01/26/2011 01:32 Mineraku12#5
Ah the second one worked flawlessly ^_^ Thanks for your swift and accurate responses
-arigatou
01/28/2011 21:24 maxhotdog#6
what can i do with this? i mean this is a script right but im not good at this things can you help me please?
01/29/2011 02:08 Kape7#7
Quote:
Originally Posted by maxhotdog View Post
what can i do with this? i mean this is a script right but im not good at this things can you help me please?
It press buttons.
01/29/2011 10:32 maxhotdog#8
yeah i know but how do i use this script can someone explain?