Sign in to follow this  
Followers 0
djnbh

SImple HOtkey question

7 posts in this topic

:lmao: 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? ;)o:)

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by ChrisL

Share this post


Link to post
Share on other sites

#3 ·  Posted (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)

While 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 by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

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 game

When "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 released

wait 2 second on the ground

Charcter gets up from the ground "Z"

Character moves right for 1 second "D" held down

Character lies downs "Z"

"D" is released

"Z" is released

Do not have to indicate autoit to release the key?

Share this post


Link to post
Share on other sites

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


[center]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.[/center]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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)

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 :lmao:

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  
Followers 0