djnbh Posted January 23, 2006 Share Posted January 23, 2006 I am totally new to autoit. and I trying to make simple hotkey macro for a game (bf2/battlfield 2) to do a certain move when a f1 key is pressed. This is what I am trying to do whenever f1 is pressed "A"(move left) for 1 second "z"(prone) "A" released wait 2 seconds "z" "D" move right for 1 second "z" (prone) "d" released wait 2 second Can anyone help? Link to comment Share on other sites More sharing options...
ChrisL Posted January 23, 2006 Share Posted January 23, 2006 (edited) Something like... AutoItSetOption ("SendKeyDownDelay",1000) HotKeySet("{F1}", "Keys") While 1 Sleep (1000) Wend Func Keys() Send ("{A}");(move left) for 1 second Send ("{z}");"z"(prone) Send ("{A}");"A" released Sleep (2000);wait 2 seconds Send ("{z}");"z" Send ("{D}");"D" move right for 1 second Send ("{z}");"z" (prone) Send ("{d}");"d" released Sleep (2000);wait 2 second EndFunc Edited January 23, 2006 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 23, 2006 Moderators Share Posted January 23, 2006 (edited) Something like... AutoItSetOption ("SendKeyDownDelay",1000) HotKeySet("{F1}", "Keys") While 1 Sleep (1000) Wend Func Keys() Send ("{A}");(move left) for 1 second Send ("{z}");"z"(prone) Send ("{A}");"A" released Sleep (2000);wait 2 seconds Send ("{z}");"z" Send ("{D}");"D" move right for 1 second Send ("{z}");"z" (prone) Send ("{d}");"d" released Sleep (2000);wait 2 second EndFunc Dude... Is that what he means... I'm sitting here trying to write these hotkeysets(), trying to think what the hell prone is... and if he needs hotkeys why is he putting 'A' Released.... P.S. Why do you have curly brackets around your letters, is there some significance?? EDIT See this is what I thought he had in mind, but yours makes more sense (Might want to edit the curly brackets though)expandcollapse popupWhile 1 If _IsPressed('41') Then While _IsPressed('41') Local $Timer = TimerInit() Do Local $Pos = MouseGetPos() For $i = 1 To 1000 Step 2 MouseMove($Pos[0] - $i, $Pos[1], 0) If TimerDiff($Timer) / 1000 >= 1 Then ExitLoop Next Until TimerDiff($Timer) / 1000 >= 1; 1 is 1 second Send('z') WEnd Sleep(2000) EndIf If _IsPressed('44') Then While _IsPressed('44') Local $Timer = TimerInit() Do Local $Pos = MouseGetPos() For $i = 1 To 1000 Step 2 MouseMove($Pos[0] + $i, $Pos[1], 0) If TimerDiff($Timer) / 1000 >= 1 Then ExitLoop Next Until TimerDiff($Timer) / 1000 >= 1; 1 is 1 second Send('z') WEnd Sleep(2000) EndIf Sleep(10) WEnd Func _IsPressed($s_hexKey, $v_dll = 'user32.dll') Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc Edited January 23, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
djnbh Posted January 23, 2006 Author Share Posted January 23, 2006 Dude... Is that what he means... I'm sitting here trying to write these hotkeysets(), trying to think what the hell prone is... and if he needs hotkeys why is he putting 'A' Released.... P.S. Why do you have curly brackets around your letters, is there some significance??Ok.i am at work and unable to try these codes out until i get home.This is what I am trying to do do with BF2 (Battlefield 2) 1st person shooting gameWhen "F1" is pressed.Character Moves "left" for 1 second ("A" button has to held down for 1 second)Character lies on the grond(Prone) "Z""A" is released"Z" is releasedwait 2 second on the groundCharcter gets up from the ground "Z"Character moves right for 1 second "D" held downCharacter lies downs "Z""D" is released"Z" is releasedDo not have to indicate autoit to release the key? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 23, 2006 Moderators Share Posted January 23, 2006 Hell, I'm still totally guessing here, wish I played games sometimes: HotKeySet('{F1}', 'StartTest') While 1 Sleep(0x7FFFFFF) WEnd Func StartTest() Local $Timer = TimerInit() Local $OPT = Opt('SENDKEYDOWNDELAY', 50) Do Send('A') Until TimerDiff($Timer) / 1000 >= 1 Opt('SENDKEYDOWNDELAY', $OPT) Send('AZ') Sleep(2000) Send('Z') $Timer = TimerInit() $OPT = Opt('SENDKEYDOWNDELAY', 50) Do Send('D') Until TimerDiff($Timer) / 1000 >= 1 Opt('SENDKEYDOWNDELAY', $OPT) Send('DZ') Sleep(2000) Send('Z') EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
djnbh Posted January 23, 2006 Author Share Posted January 23, 2006 Hell, I'm still totally guessing here, wish I played games sometimes: HotKeySet('{F1}', 'StartTest') While 1 Sleep(0x7FFFFFF) WEnd Func StartTest() Local $Timer = TimerInit() Local $OPT = Opt('SENDKEYDOWNDELAY', 50) Do Send('A') Until TimerDiff($Timer) / 1000 >= 1 Opt('SENDKEYDOWNDELAY', $OPT) Send('AZ') Sleep(2000) Send('Z') $Timer = TimerInit() $OPT = Opt('SENDKEYDOWNDELAY', 50) Do Send('D') Until TimerDiff($Timer) / 1000 >= 1 Opt('SENDKEYDOWNDELAY', $OPT) Send('DZ') Sleep(2000) Send('Z') EndFunc Thank you very much Somke_N Your code looks very professional and looks almighty. I will certainly try your codes out tonight and let you know of the outcome of it. Meanwhile let me explain how the games works so that you can visualize it better if want to. Battlefield 2 is first-person shooting game. (like Doom, Counter-strike, and quake etc) you would be looking at the screen as if a person would be looking out front. there are 4 directional keys "W,A,D,S" and other movement keys "Z" (if pressed you would lie flat on a ground) "Space Bar" (Jump) etc. W -> moves forward A > moves left D -> moves right S -> movers backwrad when opponent person is encountered I wanted to the game character to move to the certain directions so that opponents have difficult time to aim and and shoot, (when F1 key is pressed). "A" is held down the chacter will move left as long is "A" is held down Same with other directional keys. "Z" is pressed once character will lie down on a ground. "Z" is pressed when the character is lied down it will make character stand up. The macro I was intended to create would do something like this when "F1" is pressed character will move left for 1 second and lie down (wait for 2 second so I can take an aim and shoot) Get up, moves to right for 1 second and lie down again. ' I hope this might help you to understand what i am trying to do. Link to comment Share on other sites More sharing options...
ChrisL Posted January 23, 2006 Share Posted January 23, 2006 Dude... Is that what he means... I'm sitting here trying to write these hotkeysets(), trying to think what the hell prone is... and if he needs hotkeys why is he putting 'A' Released.... P.S. Why do you have curly brackets around your letters, is there some significance??EDITSee this is what I thought he had in mind, but yours makes more sense (Might want to edit the curly brackets though)I really don't know mate.. I read it and thought that was what he was after.. as for the curley brackets, I hadn't been looking at the help file and just chucked curly's round, I ran the script with a notepad window open and it sent the keys so I just left it at that, maybe its a reminance of AutoIT2 or something else.. who knows!I feel another $IAmAnArse=1 variable coming on [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now