Jump to content
Sign in to follow this  
arkane

Send space twice

Recommended Posts

arkane

Hi dudes.

I have a problem with my script.

#include <Misc.au3>

If _IsPressed('11') Then
    $i=0
    While $i = 2
        Send("{SPACE down}")
        sleep (300)
        Send("{Space up}")
        $i = $i + 1
    WEnd
EndIf

I want that when I press ctrl, space is pressed twice.

But when I compile my project and launch it, nothing his launched, or maybe it is automaticly and quickly closed by itself.

Do you have any idea why ?

Thanks in advance.

Share this post


Link to post
Share on other sites
FireFox

@arkane

#include <Misc.au3>
 
 If _IsPressed('11') Then
     $i=0
     While $i <= 2
         Send("{SPACE down}")
         sleep (300)
         Send("{Space up}")
         $i = $i + 1
     WEnd
 EndIf

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
spudw2k

Hi dudes.

I have a problem with my script.

#include <Misc.au3>

If _IsPressed('11') Then
    $i=0
    While $i = 2
        Send("{SPACE down}")
        sleep (300)
        Send("{Space up}")
        $i = $i + 1
    WEnd
EndIf

I want that when I press ctrl, space is pressed twice.

But when I compile my project and launch it, nothing his launched, or maybe it is automaticly and quickly closed by itself.

Do you have any idea why ?

Thanks in advance.

Well, While i = 2 never happens cause i = 0. Try While i < 2?

Share this post


Link to post
Share on other sites
SpookMeister

Because you do not have your script wait until you press control.

It just reads through the script... sees that _Ispressed('11') is not pressed at that split second of time, then it ends.

You need to do a loop..

#include <Misc.au3>
HotKeySet("{ESC}", "Terminate")

While 1
    Sleep(100) ; always a good idea so you dont max your cpu
    If _IsPressed('11') Then
        $i = 0
        While $i < 2
            Send("{SPACE down}")
            Sleep(300)
            Send("{Space up}")
            $i = $i + 1
        WEnd
    EndIf
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

[edit] tweaked your other while loop so it would work too[/edit]

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
arkane

wow !

what quick answers ! lol !

Thanks for your help, that was a syntax error :)...

But well, it seems to work very slowly !!

I just want to convert this ahk script into an autoit one :

LControl & RAlt::
Loop 2
{
Sendinput {Space down}
sleep 30
Sendinput {Space up}
}
Return

but I'm struggling :lmao:

Edit : In fact, I want to use this for a game which use 60fps.

I would like that on one frame it press space, and just on the next one, it press space again.

Edited by arkane

Share this post


Link to post
Share on other sites
SpookMeister

what is slow?

The response to pressing CTRL?

The time between spaces?

How long it is taking to do each space?


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
SpookMeister

Then tweak it...

#include <Misc.au3>
HotKeySet("{ESC}", "Terminate")

While 1
    Sleep(10) ; always a good idea so you dont max your cpu
    If _IsPressed('11') Then
        $i = 0
        While $i = 2
            Send("{SPACE down}")
            Sleep(20) ; 60 FPS means you will have a frame every 16.666666... miliseconds
            Send("{Space up}")
            $i = $i + 1
        WEnd
    EndIf
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
arkane

well, the problem is that it doesn't answer everytime I press control.

Is there any way to set ALTGR key instead of control ?

I tried

#include <Misc.au3>

While 1
    If _IsPressed('!Gr') Then
        $i = 0
        While $i <= 2
            Send("{SPACE down}")
            Sleep(17); 60 FPS means you will have a frame every 16.666666... miliseconds
            Send("{Space up}")
            $i = $i + 1
        WEnd
    EndIf
WEnd

but it doesn't work :/

Edited by arkane

Share this post


Link to post
Share on other sites
SpookMeister

How about:

#include <Misc.au3>
HotKeySet("{ESC}", "Terminate")

While 1
    Sleep(10) ; always a good idea so you dont max your cpu
    If _IsPressed('11') Then
        $i = 0
        While $i = 2
            Send("{SPACE}")
            Sleep(20)
            Send("{SPACE}")
            $i = $i + 1
        WEnd
    EndIf
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
SpookMeister

Try this, and play with the OPT values

#include <Misc.au3>
HotKeySet("{ESC}", "Terminate")
Opt ("SendKeyDelay",15) ; delay between sending keys - default 5
Opt ("SendKeyDownDelay",5) ; how long to hold down a key - default 5

While 1
    Sleep(10) ; always a good idea so you dont max your cpu
    If _IsPressed('11') Then Send ("{SPACE}{SPACE}") ; '11' = a CTRL key
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
SpookMeister

FYI, on my machine checking _IsPressed() takes about 5 miliseconds all by itself... YMMV "Your Mileage May Vary"


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.