Jump to content

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


chropose
 Share

Recommended Posts

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

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

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

Edited by chropose
Link to comment
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

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

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

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...