Sign in to follow this  
Followers 0
chropose

[Solved] How to press "something" for 2 secs, stop for 1 secs?

16 posts in this topic

#1 ·  Posted (edited)

I found the answer:

while 1

ControlSend("Untitled", "", "Edit1", "{a down}")

Sleep(2000)

ControlSend("Untitled", "", "Edit1", "{a up}")

Sleep(1000)

wend

thanks to Tvern for reminding me of ControlSend

Edited by chropose

Share this post


Link to post
Share on other sites



ummm try to be a little more clear do you mean hold the mouse down for 2 sec then stop for 1 or click repeatedly for 2 sec then stop or what exactly are you tryin to do =\

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

sorry, i mean to press something on keyboard, let's say i wanna have notepad to press and hold "H" for 2 secs and then stop pressing for 1 sec, continuously in loop.

Edited by chropose

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

sorry, i mean to press something on keyboard, let's say i wanna have notepad to press and hold "H" for 2 secs and then stop pressing for 1 sec, continuously in loop.

while 1

send("{a down}")

sleep(2000)

send("{a up}")

sleep(1000)

wend

replace a with whatever key on the keyboard u want

Edited by norax

Share this post


Link to post
Share on other sites

thanks. ill try it now.

Share this post


Link to post
Share on other sites

hey, thanks it worked.

btw, how to specify this script to work only on a specific program?

let's say i wanted this script to work only on notepad so when i changed the window focus to browser address bar, the script didnt do anything to interrupt it.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

hey, thanks it worked.

btw, how to specify this script to work only on a specific program?

let's say i wanted this script to work only on notepad so when i changed the window focus to browser address bar, the script didnt do anything to interrupt it.

Try this:

While 1
    Sleep(200)
    if WinActive("[CLASS:Notepad]") = NOT 0 Then
        Send("{a down}")
        Sleep(2000)
        Send("{a up}")
        Sleep(1000)
    EndIf
WEnd
Edited by UnDeFiNeD

Share this post


Link to post
Share on other sites

undefined,

i tried that script, it doesnt work. it only makes the script working if window focus is currently on notepad. if the focus changed, nothing happens at all.

Share this post


Link to post
Share on other sites

undefined,

i tried that script, it doesnt work. it only makes the script working if window focus is currently on notepad. if the focus changed, nothing happens at all.

While 1
    Sleep(200)
    if WinActive("your programs window title here") Then
        Send("{a down}")
        Sleep(2000)
        Send("{a up}")
        Sleep(1000)
    EndIf
WEnd

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

While 1
    Sleep(200)
    if WinActive("your programs window title here") Then
        Send("{a down}")
        Sleep(2000)
        Send("{a up}")
        Sleep(1000)
    EndIf
WEnd

norax,

if the current window is on "untitled" (Notepad), the script work and only works if the window is on untitled. if the focus changed nothing happens. still same like undefined's script.

Edited by chropose

Share this post


Link to post
Share on other sites

While 1
    Sleep(200)
    if WinActive("your programs window title here") Then
        Send("{a down}")
        Sleep(2000)
        Send("{a up}")
        Sleep(1000)
    EndIf
WEnd

norax,

if the current window is on "untitled" (Notepad), the script work and only works if the window is on untitled. if the focus changed nothing happens. still same like undefined's script.

im not sure what your wanting it to do then. if you want it to only not run on a specific window then do this

While 1
    Sleep(200)
    if WinActive("program title here") Then
        Sleep(250)
    Else
        Send("{a down}")
        Sleep(2000)
        Send("{a up}")
        Sleep(1000)
    EndIf
WEnd

if this is not it then ill need a better explanation of what you want lol

Share this post


Link to post
Share on other sites

If you want to a window, even if that window is not the active one, replace Send() with ControlSend(). The helpfile has an example using notepad.

Share this post


Link to post
Share on other sites

undefined,

i tried that script, it doesnt work. it only makes the script working if window focus is currently on notepad. if the focus changed, nothing happens at all.

You said "let's say i wanted this script to work only on notepad"

Share this post


Link to post
Share on other sites

You said "let's say i wanted this script to work only on notepad"

let's say i wanted this script to work only on notepad so when i changed the window focus to browser address bar, the script didnt do anything to interrupt it.

Share this post


Link to post
Share on other sites

i've tried adding "Control" so it becomes ControlSend:

While 1
    Sleep(200)
    if WinActive("[CLASS:Notepad]") = NOT 0 Then
        ControlSend("{a down}")
        Sleep(2000)
        ControlSend("{a up}")
        Sleep(1000)
    EndIf
WEnd

and this:

While 1
    Sleep(200)
    if WinActive("Untitled") Then
        ControlSend("{a down}")
        Sleep(2000)
        ControlSend("{a up}")
        Sleep(1000)
    EndIf
WEnd

and also:

While 1
    Sleep(200)
    if WinActive("Untitled") Then
        Sleep(250)
    Else
        ControlSend("{a down}")
        Sleep(2000)
        ControlSend("{a up}")
        Sleep(1000)
    EndIf
WEnd

all of them doesn't work.

Share this post


Link to post
Share on other sites

i've tried adding "Control" so it becomes ControlSend:

...

all of them doesn't work.

They wouldn't because ControlSend() has more parameters than Send().

Like I said the helpfile for ControlSend() has an example specifically for notepad.

All you need to do is replace Send with that example and then change the example text with your own.

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