Jump to content

Extreme Newbie Question


Recommended Posts

Yes, I'm sure you see this scenario quite often. A low poster putting a question that probably has an extremely obvious answer, so simple in fact you would rather place your palm on your face rather than answer it. I have nothing to lose though, so I'll keep this brief, but as respectfully grammatical as possible.

I'm trying to run a simple code that will hold a key down for a certain amount of time, release, then repeat the process. I tried using the code from this thread, which looks like exactly the same question.

Kinda hard to read what they're saying, but I pretty much got it after a while. So just to test it, I tried out this modification to the code, according to what the thread says, would hold space bar, release, and repeat, while on the "Documents" folder. The space bar would merely highlight the file, so nothing would really happen.

A note, I'm running a new vista. Don't know how much it affects it. Probably a lot.

While 1
    Sleep(200)
    if WinActive("Documents") Then
        Sleep(250)
    Else
        Send("{SPACE down}")
        Sleep(2000)
        Send("{SPACE up}")
        Sleep(1000)
    EndIf
WEnd

Now, looking at other forums, I notice the 'key' to doing the entire code is just...

Send("{SPACE down}")
Sleep(2000)
Send("{SPACE up}")

As that's the command that makes the key go down and up in the first place.

Now, the thing is.....it runs fine, but simply nothing happens. I try it also on notepad, and nothing is typed. Now, where I think I have a problem.

I try this tutorial just to make sure what I'm doing is right.

http://www.autoitscript.com/autoit3/docs/tutorials/notepad/notepad.htm

I put it in notepad, save as .au3, and liftoff.....It sort of works. The code opens notepad, but doesn't type anything in. It opens then immediately closes. The code being....

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!n")

So I'm thinking something's up with my computer, and not the coding. I now proceed to badgering you all in a polite manner, until a suggestion helps.

If you need any more info, please ask. Saying I'm an AutoIt noob would be an understatement. I look at all these help threads, and I just kind of....faze out in confusion.

Only one thing I ask....please don't "direct me to some tutorial to help me get started". I find that insulting, for one, and not very helpful overall. Although reading these other topics, you all seem patient with dimwits and the such, so that makes me feel safe enough.

Proceed with the assisting.

Link to comment
Share on other sites

You can try something like this, but I'm not sure if it's what you want. If you want to continuously send the space bar for 2 seconds, you'll need it inside a loop because it actually will only send it once (for your situation). I think if you were holding down the Alt key, you could hit the F4 key and it would send the close window command to the active window, but I don't think that is what you want. For example, if you sent the {a down} key to notepad (outside of a loop) it would actually only type "a" once, then release. To be honest, for what I think you want you could just as easily send {SPACE} without the down an it would serve the same purpose. Anyways, this script will send the Space down for up to 2 seconds, then pause 1 second, and repeat. If focus is lost on your window, the script will wait for your window to become active again before resuming. Also note my window definition "Title & Class". I am on Windows 7, but make sure that you use the AU3Info Tool to get the proper window Title with which you are trying to interact. I also used the SendKeyDownDelay option since it may help you tweak the script to suit your needs. Lastly, I used ControlSend() instead of Send so I don't accidentally send the keystrokes to another window if my intended window looses activation.

Opt('SendKeyDownDelay', 50)
$wTitle = '[TITLE:Libraries\Documents; CLASS:CabinetWClass]'
While 1
    WinWaitActive($wTitle)
    $TimeStart = TimerInit()
    Do
        ControlSend($wTitle, '', '', "{SPACE down}")
    Until Not WinActive($wTitle) Or TimerDiff($TimeStart) >= 2000
    Send("{SPACE up}")
    Sleep(1000)
WEnd

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