scripterman Posted April 5, 2010 Share Posted April 5, 2010 hello to everyone in the forum I want to create a quite simple script. I need to control another window (already open) and as soon as I run the script, I need the SPACE button to be held down for a specific amount of time (defined by me), then released, then held again etc. I had in mind something like this: WinWaitActive("Window Title") Send("{SPACE down}") Sleep(2000); If I want it to be held for 2 seconds Send("{SPACE up}") Sleep(1000); to wait 1 sec before it is pressed again and so on.. But it doesn't seem to work. Why? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 5, 2010 Moderators Share Posted April 5, 2010 scripterman,What is the window that you are trying to Send to?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
scripterman Posted April 5, 2010 Author Share Posted April 5, 2010 A mozilla firefox window. I used the AutoIt Window Info to copy-paste the exact name of the window.. But it doesn't work. Actually, I'm not sure 10% how the WinWaitActive command works. I mean: - I'm in the AutoIt window writing the script and I press Go (or F5) - Do I have to make the specific mozilla firefox window active myself by clicking in it? Then will the script start executing the commands? Is the rest of the script ok? Thanks Link to comment Share on other sites More sharing options...
GiulioM Posted April 5, 2010 Share Posted April 5, 2010 (edited) [...] I had in mind something like this: WinWaitActive("Window Title") Send("{SPACE down}") Sleep(2000); If I want it to be held for 2 seconds Send("{SPACE up}") Sleep(1000); to wait 1 sec before it is pressed again and so on.. But it doesn't seem to work. Why? Because Sleep() means "pause the script", so pauses Send() command too. I suggest this code to solve the problem: WinWaitActive("Window Title") Dim $stop_send = @sec + 2 ; Change me!!! Do Send("{SPACE}") Until @SEC = $stop_send Sleep(1000) Send("{SPACE}) p.s. I've checked the code on SciTe, I've not written it now (like I do usually =) ). Edited April 5, 2010 by GiulioM Link to comment Share on other sites More sharing options...
scripterman Posted April 5, 2010 Author Share Posted April 5, 2010 Hmmm.. It DOES send the Space key, but it doesn't hold it down for 2 seconds like I wanted to. It seems to just a press of the key. I changed the Send("{SPACE}") to Send("{SPACE down}") but it still doesn't work.. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 5, 2010 Moderators Share Posted April 5, 2010 scripterman,Holding keys down is not that easy. Try this (you will need to click in the Firefox window to activate it):WinActivate("Window Title") WinWaitActive("Window Title") $iOldOpt = Opt("SendKeyDownDelay", 2000) Send("{SPACE}") Opt("SendKeyDownDelay", $iOldOpt) Sleep(1000); to wait 1 sec before it is pressed againThe Opt lines are saving the current setting of "the length of time a key is held down before being released during a keystroke" value, changing it to 2 secs and then resetting it.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
scripterman Posted April 5, 2010 Author Share Posted April 5, 2010 Would it be easier if I told you that I could have the same result just by holding down the left mouse button instead of the space key? Link to comment Share on other sites More sharing options...
ShawnW Posted April 5, 2010 Share Posted April 5, 2010 You know I can't get the holding a button thing to work either but the left mouse click down works fine. MouseDown ("left") Sleep(2000) MouseUp("left") Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now