Jump to content

Something wrong with my code Help!


Blindz
 Share

Recommended Posts

Hi.. here's my code :

#include <misc.au3>

HotKeySet("{F7}","Shoot")

$dll = DllOpen("user32.dll")

While 1

sleep (1)

If _IsPressed("20", $dll) Then

$start = TimerInit()

ExitLoop

EndIf

WEnd

While _IsPressed ( "20", $dll )

Sleep(1)

WEnd

$temps = TimerDiff($start)

Func Shoot()

Send("{SPACE down}")

Sleep ($temps)

Send ("{space up}")

EndFunc

While 1

Sleep (1)

Wend

DllClose($dll)

where's the function Shoot... the sleep doesnt seems to work good cuz is doesnt press space the same time that i press on it... whats wrong? thanks

Link to comment
Share on other sites

Try compiling this

#include <misc.au3>
AutoItSetOption("MustDeclareVars", 1)

HotKeySet("{F7}", "Shoot")

$dll = DllOpen("user32.dll")

While 1
    Sleep(1)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        ExitLoop
    EndIf
WEnd

While _IsPressed("20", $dll)
    Sleep(1) 
WEnd

$temps = TimerDiff($start)

Func Shoot()
    Send("{SPACE down}")
    Sleep($temps)
    Send("{space up}")
EndFunc   ;==>Shoot

While 1
    Sleep(1)
WEnd

DllClose($dll)

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Try compiling this

#include <misc.au3>
AutoItSetOption("MustDeclareVars", 1)

HotKeySet("{F7}", "Shoot")

$dll = DllOpen("user32.dll")

While 1
    Sleep(1)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        ExitLoop
    EndIf
WEnd

While _IsPressed("20", $dll)
    Sleep(1) 
WEnd

$temps = TimerDiff($start)

Func Shoot()
    Send("{SPACE down}")
    Sleep($temps)
    Send("{space up}")
EndFunc   ;==>Shoot

While 1
    Sleep(1)
WEnd

DllClose($dll)

C:\Documents and Settings\Blind\Mes documents\Space Shoot Gb.au3 (6) : ==> Variable used without being declared.:

$dll = DllOpen("user32.dll")

^ ERROR

doesn't work :D

Link to comment
Share on other sites

You have mustdeclarevars set to 1, add local $dll to the start of your script and it should work(I think).

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

I know, thats because you are using vars with out declaring - not a good idea. I recommend using AutoItSetOption("MustDeclareVars", 1)

When I ran it and pressed F7, I get

==> Variable used without being declared.:

Sleep($temps)

Sleep(^ ERROR

which means $temps has never been set. When it is run, it sits in the While loop, then when F7 is pressed, it goes to Shoot() where $temps is not set ($temps = TimerDiff($start) is not run).

Not sure what you are trying to do, but give this a crack

#include <misc.au3>
AutoItSetOption("MustDeclareV ars", 1)

HotKeySet("{F7}", "Shoot")

Local $dll = DllOpen("user32.dll")
Local $start = TimerInit()
Local $temps = TimerDiff($start)

While 1
    Sleep(1)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        ExitLoop
    EndIf
WEnd

While _IsPressed("20", $dll)
    Sleep(1) 
WEnd

$temps = TimerDiff($start)

Func Shoot()
    Send("{SPACE down}")
    Sleep($temps)
    Send("{space up}")
EndFunc   ;==>Shoot

While 1
    Sleep(1)
WEnd                        

DllClose($dll)
Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

hmm when i press F7 it doesn't press enter the same time that i did

And why would it, it presses space. Send("{Enter}") is not in the code.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Sorry, but I really don't get what your trying to do. In the first post you said it doesn't work because it doesn't press space at the same time you do. From what I can see the code you had in the first post would start a timer when you press space, wait until you release space, check the timer, and then press space for just as long as you did. Please give a better explanation of what your trying to do.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Sorry, but I really don't get what your trying to do. In the first post you said it doesn't work because it doesn't press space at the same time you do. From what I can see the code you had in the first post would start a timer when you press space, wait until you release space, check the timer, and then press space for just as long as you did. Please give a better explanation of what your trying to do.

Alright... Exemple: i press Space ... Timer start ... i release space ...Timer as count 2secs ...now When i press F7... it check how many sec i pressed Space (in this exemple 2secs) then press space for 2sec... and then if i press F7 again it will press space for 2secs again.. and again ...Config stay same until i press space

makes more sence?

Link to comment
Share on other sites

That script looks like it only checks for space once. Try this.

#include <misc.au3>

HotKeySet("{F7}", "Shoot")

Local $dll = DllOpen("user32.dll"), $start, $temps = 0


While 1
    Sleep(10)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        While _IsPressed("20", $dll)
            Sleep(10) 
        WEnd
        $temps = TimerDiff($start)
    EndIf
WEnd


Func Shoot()
    Send("{SPACE down}")
    Sleep($temps)
    Send("{space up}")
EndFunc

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

That script looks like it only checks for space once. Try this.

#include <misc.au3>

HotKeySet("{F7}", "Shoot")

Local $dll = DllOpen("user32.dll"), $start, $temps = 0


While 1
    Sleep(10)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        While _IsPressed("20", $dll)
            Sleep(10) 
        WEnd
        $temps = TimerDiff($start)
    EndIf
WEnd


Func Shoot()
    Send("{SPACE down}")
    Sleep($temps)
    Send("{space up}")
EndFunc

i dont really know why but even if i press space for 10sec when i press f7 it only make 1 space!! is this normal? loll
Link to comment
Share on other sites

If it has space down for 10 seconds windows should repeatedly send space every $x seconds depending on your keyboard configuration.

Edit: Hmm, just tested it, strange, it does only send one space.

Edit2: Just a wild guess, but maybe it's cause the {key down} functions where made for modifier keys, so when you do {altdown} and hit F5 in SciTE it runs script with beta.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Try this.

#include <misc.au3>

$frequency = 100 ; how often to hit space

HotKeySet("{F7}", "Shoot")

Local $dll = DllOpen("user32.dll"), $start, $temps = 0


While 1
    Sleep(10)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        While _IsPressed("20", $dll)
            Sleep(10)
        WEnd
        $temps = TimerDiff($start)
    EndIf
WEnd


Func Shoot()
    $start2 = TimerInit()
    While TimerDiff($start2) <= $temps
        Send("{space}")
        Sleep($frequency)
    WEnd
EndFunc

You'll have to set $frequency, you might be able to get the keyboard config value for it in the registry somewhere, but I'm not gonna bother looking for it now.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Try this.

#include <misc.au3>

$frequency = 100 ; how often to hit space

HotKeySet("{F7}", "Shoot")

Local $dll = DllOpen("user32.dll"), $start, $temps = 0


While 1
    Sleep(10)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        While _IsPressed("20", $dll)
            Sleep(10)
        WEnd
        $temps = TimerDiff($start)
    EndIf
WEnd


Func Shoot()
    $start2 = TimerInit()
    While TimerDiff($start2) <= $temps
        Send("{space}")
        Sleep($frequency)
    WEnd
EndFunc

You'll have to set $frequency, you might be able to get the keyboard config value for it in the registry somewhere, but I'm not gonna bother looking for it now.

seems working but doesnt press the same lenght!! Edited by Blindz
Link to comment
Share on other sites

If you want it to repeat at the same rate as the keyboard does, you'll probably want to find where that value is in the registry. You'll also want to add in a delay before it starts repeating.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Well it works fine for me, there is the slight problem that sometimes when you only send 1 space, it sends 2 or 3 because I didn't make a delay before it starts repeating, but its working just fine other than that.

Yea true but if i only press space once its not gonna work :D the reason why i want that its for my game Gunbound... i press space shoot some one and when i press f7 it remake the same shot i just did...

Link to comment
Share on other sites

If you find the delay and repeat frequency values, you can put them in place of $delay and $frequency in this script.

#include <misc.au3>

$first = 1
$delay = 500 ; delay before it starts repeating
$frequency = 100 ; how often to hit space

HotKeySet("{F7}", "Shoot")

Local $dll = DllOpen("user32.dll"), $start, $temps = 0


While 1
    Sleep(10)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        While _IsPressed("20", $dll)
            Sleep(10)
        WEnd
        $temps = TimerDiff($start)
    EndIf
WEnd


Func Shoot()
    $start2 = TimerInit()
    While TimerDiff($start2) <= $temps
        Send("{space}")
        If $first = 1 Then
            Sleep($delay - $frequency)
            $first = 0
        EndIf
        Sleep($frequency)
    WEnd
    $first = 1
EndFunc

other than that, I can't really help you.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

If you find the delay and repeat frequency values, you can put them in place of $delay and $frequency in this script.

#include <misc.au3>

$first = 1
$delay = 500 ; delay before it starts repeating
$frequency = 100 ; how often to hit space

HotKeySet("{F7}", "Shoot")

Local $dll = DllOpen("user32.dll"), $start, $temps = 0


While 1
    Sleep(10)
    If _IsPressed("20", $dll) Then
        $start = TimerInit()
        While _IsPressed("20", $dll)
            Sleep(10)
        WEnd
        $temps = TimerDiff($start)
    EndIf
WEnd


Func Shoot()
    $start2 = TimerInit()
    While TimerDiff($start2) <= $temps
        Send("{space}")
        If $first = 1 Then
            Sleep($delay - $frequency)
            $first = 0
        EndIf
        Sleep($frequency)
    WEnd
    $first = 1
EndFunc

other than that, I can't really help you.

Alright then thanks so much man!!! i really apreciate all of your help!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...